Yet another try to fix the LCD corruption

It turns out that the ChibiOS K20 SPI driver doesn't handle the
chip select, so it needs to be done manually. Acquiring the bus is
not enough since the pin was in the wrong mode. This is now fixed.

Also increase the frequency of the SPI from around 200kHz to nearly
20 Mhz.
This commit is contained in:
Fred Sundvik 2017-04-07 10:51:53 +03:00
parent b7041d06ae
commit 3994fb1e79

View File

@ -45,15 +45,28 @@ static const SPIConfig spi1config = {
.sspad=ST7565_SS_PIN, .sspad=ST7565_SS_PIN,
// SPI initialization data. // SPI initialization data.
.tar0 = .tar0 =
SPIx_CTARn_FMSZ(7) SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes
| SPIx_CTARn_ASC(7) | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns
| SPIx_CTARn_DT(7) | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns
| SPIx_CTARn_CSSCK(7) | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns
| SPIx_CTARn_PBR(0) | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2
| SPIx_CTARn_BR(7) | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns
//SPI_CR1_BR_0
}; };
static GFXINLINE void acquire_bus(GDisplay *g) {
(void) g;
// Only the LCD is using the SPI bus, so no need to acquire
// spiAcquireBus(&SPID1);
spiSelect(&SPID1);
}
static GFXINLINE void release_bus(GDisplay *g) {
(void) g;
// Only the LCD is using the SPI bus, so no need to release
//spiReleaseBus(&SPID1);
spiUnselect(&SPID1);
}
static GFXINLINE void init_board(GDisplay *g) { static GFXINLINE void init_board(GDisplay *g) {
(void) g; (void) g;
palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL); palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL);
@ -62,10 +75,11 @@ static GFXINLINE void init_board(GDisplay *g) {
palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN); palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN);
palSetPadModeRaw(MOSI, ST7565_SPI_MODE); palSetPadModeRaw(MOSI, ST7565_SPI_MODE);
palSetPadModeRaw(SLCK, ST7565_SPI_MODE); palSetPadModeRaw(SLCK, ST7565_SPI_MODE);
palSetPadModeRaw(SS, ST7565_SPI_MODE); palSetPadModeRaw(SS, PAL_MODE_OUTPUT_PUSHPULL);
spiInit(); spiInit();
spiStart(&SPID1, &spi1config); spiStart(&SPID1, &spi1config);
release_bus(g);
} }
static GFXINLINE void post_init_board(GDisplay *g) { static GFXINLINE void post_init_board(GDisplay *g) {
@ -82,20 +96,6 @@ static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) {
} }
} }
static GFXINLINE void acquire_bus(GDisplay *g) {
(void) g;
// Only the LCD is using the SPI bus, so no need to acquire
// spiAcquireBus(&SPID1);
spiSelect(&SPID1);
}
static GFXINLINE void release_bus(GDisplay *g) {
(void) g;
// Only the LCD is using the SPI bus, so no need to release
//spiReleaseBus(&SPID1);
spiUnselect(&SPID1);
}
static GFXINLINE void enter_data_mode(GDisplay *g) { static GFXINLINE void enter_data_mode(GDisplay *g) {
palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN);
} }