1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
#ifndef GAUDIO_PLAY_BOARD_H
#define GAUDIO_PLAY_BOARD_H
#define SET_CS palSetPad(GPIOC, GPIOC_MP3_CS)
#define CLR_CS palClearPad(GPIOC, GPIOC_MP3_CS)
#define SET_RST palSetPad(GPIOC, GPIOC_MP3_RST)
#define CLR_RST palClearPad(GPIOC, GPIOC_MP3_RST)
#define SET_DCS palSetPad(GPIOC, GPIOC_MP3_DCS)
#define CLR_DCS palClearPad(GPIOC, GPIOC_MP3_DCS)
#define GET_DREQ palReadPad(GPIOC, GPIOC_MP3_DREQ)
#define SPI_PORT &SPID3
static const SPIConfig spicfg_init = {
0,
GPIOC,
GPIOC_MP3_CS,
SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
};
static const SPIConfig spicfg = {
0,
GPIOC,
GPIOC_MP3_CS,
SPI_CR1_BR_0,
};
// Initialise the board
static GFXINLINE void board_init(void) {
palSetPadMode(GPIOC, GPIOC_MP3_CS, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOC, GPIOC_MP3_RST, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOC, GPIOC_MP3_DCS, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOC, GPIOC_MP3_DREQ, PAL_MODE_INPUT);
SET_CS; SET_RST; SET_DCS;
spiStart(SPI_PORT, &spicfg_init);
}
// Chip is initialised enough so we can talk fast to it
#define board_init_end() spiStart(SPI_PORT, &spicfg)
// Reset the board
#define board_reset() { CLR_RST; gfxSleepMilliseconds(1); SET_RST; }
// Returns the state of the dreq pin
#define board_dreq() GET_DREQ
// Start a command write
static GFXINLINE void board_startcmdwrite(void) {
#if SPI_USE_MUTUAL_EXCLUSION
spiAcquireBus(SPI_PORT);
#endif
CLR_CS;
}
// End a command write
static GFXINLINE void board_endcmdwrite(void) {
SET_CS;
#if SPI_USE_MUTUAL_EXCLUSION
spiReleaseBus(SPI_PORT);
#endif
}
// Start a command read
#define board_startcmdread() board_startcmdwrite()
// End a command read
#define board_endcmdread() board_endcmdwrite()
// Start a data write
static GFXINLINE void board_startdatawrite(void) {
#if SPI_USE_MUTUAL_EXCLUSION
spiAcquireBus(SPI_PORT);
#endif
CLR_DCS;
}
// End a data write
static GFXINLINE void board_enddatawrite(void) {
#if SPI_USE_MUTUAL_EXCLUSION
spiReleaseBus(SPI_PORT);
#endif
SET_DCS;
}
// Write data to the SPI port
#define board_spiwrite(buf, len) spiSend(SPI_PORT, len, buf)
// Read data from the SPI port
#define board_spiread(buf, len) spiReceive(SPI_PORT, len, buf)
#endif /* GAUDIO_PLAY_BOARD_H */
|