2014-04-29 06:35:57 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*
|
2018-10-01 15:32:39 +00:00
|
|
|
* http://ugfx.io/license.html
|
2014-04-29 06:35:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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,
|
2014-04-30 21:20:19 +00:00
|
|
|
SPI_CR1_BR_0,
|
2014-04-29 06:35:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Initialise the board
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void board_init(void) {
|
2014-04-29 06:35:57 +00:00
|
|
|
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
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void board_startcmdwrite(void) {
|
2014-04-29 06:35:57 +00:00
|
|
|
#if SPI_USE_MUTUAL_EXCLUSION
|
|
|
|
spiAcquireBus(SPI_PORT);
|
|
|
|
#endif
|
|
|
|
CLR_CS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// End a command write
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void board_endcmdwrite(void) {
|
2014-04-30 12:57:15 +00:00
|
|
|
SET_CS;
|
2014-04-29 06:35:57 +00:00
|
|
|
#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
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void board_startdatawrite(void) {
|
2014-04-29 06:35:57 +00:00
|
|
|
#if SPI_USE_MUTUAL_EXCLUSION
|
|
|
|
spiAcquireBus(SPI_PORT);
|
|
|
|
#endif
|
|
|
|
CLR_DCS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// End a data write
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void board_enddatawrite(void) {
|
2014-04-29 06:35:57 +00:00
|
|
|
#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 */
|