boards/arm/stm32/stm32f429i-disco/src/stm32_ili93414ws.c: Appease nxstyle

This commit is contained in:
YAMAMOTO Takashi
2020-11-24 08:57:01 +09:00
committed by Xiang Xiao
parent 7b31315879
commit 048e1aab9c
@@ -109,8 +109,7 @@
# define ILI93414WS_BAUD_DIVISOR 256 # define ILI93414WS_BAUD_DIVISOR 256
#endif #endif
/* /* Permitted clock delay for a pixel transmission from the LCD gram.
* Permitted clock delay for a pixel transmission from the LCD gram.
* Calculated by cpu clock / (spi clock / baud divisor) * Calculated by cpu clock / (spi clock / baud divisor)
*/ */
@@ -126,9 +125,10 @@
#define ILI93414WS_SPI_SR (ILI93414WS_SPI_BASE + STM32_SPI_SR_OFFSET) #define ILI93414WS_SPI_SR (ILI93414WS_SPI_BASE + STM32_SPI_SR_OFFSET)
#define ILI93414WS_SPI_DR (ILI93414WS_SPI_BASE + STM32_SPI_DR_OFFSET) #define ILI93414WS_SPI_DR (ILI93414WS_SPI_BASE + STM32_SPI_DR_OFFSET)
/* Activates the usage of the spi interface structure if several active devices /* Activates the usage of the spi interface structure if several active
* connected on the SPI5 bus, e.g. LCD Display, MEMS. This will perform locking * devices connected on the SPI5 bus, e.g. LCD Display, MEMS. This will
* of the spi bus by SPI_LOCK at each selection of the SPI5 device. * perform locking of the spi bus by SPI_LOCK at each selection of the SPI5
* device.
*/ */
#ifdef CONFIG_STM32_SPI5 #ifdef CONFIG_STM32_SPI5
@@ -474,7 +474,7 @@ static int stm32_ili93414ws_sendblock(FAR struct ili93414ws_lcd_s *lcd,
{ {
/* 8-bit spi mode */ /* 8-bit spi mode */
const uint8_t *src = (const uint8_t*)wd; const uint8_t *src = (const uint8_t *)wd;
uint8_t word; uint8_t word;
while (nwords-- > 0) while (nwords-- > 0)
@@ -482,12 +482,11 @@ static int stm32_ili93414ws_sendblock(FAR struct ili93414ws_lcd_s *lcd,
word = *src++; word = *src++;
stm32_ili93414ws_sndword((uint16_t)word); stm32_ili93414ws_sndword((uint16_t)word);
} }
} }
/* Wait until transmit is not busy after the last word is transmitted, marked /* Wait until transmit is not busy after the last word is transmitted,
* by the BSY flag in the cr1 register. This is necessary if entering in halt * marked by the BSY flag in the cr1 register. This is necessary if
* mode or disable the spi periphery. * entering in halt mode or disable the spi periphery.
*/ */
while ((getreg16(ILI93414WS_SPI_SR) & SPI_SR_BSY) != 0); while ((getreg16(ILI93414WS_SPI_SR) & SPI_SR_BSY) != 0);
@@ -526,9 +525,9 @@ static uint16_t stm32_ili93414ws_recvword(void)
* immediately after enabling it. If the pixel data stream is interrupted * immediately after enabling it. If the pixel data stream is interrupted
* during receiving, a synchronized transfer can not ensure. Especially on * during receiving, a synchronized transfer can not ensure. Especially on
* higher frequency it can happen that the interrupted driver isn't fast * higher frequency it can happen that the interrupted driver isn't fast
* enough to stop transmitting by disabling the spi device. So pixels lost but * enough to stop transmitting by disabling the spi device. So pixels lost
* not recognized by the driver. This results in a big lock because the driver * but not recognized by the driver. This results in a big lock because
* wants to receive missing pixel data. * the driver wants to receive missing pixel data.
* The critical section here ensures that the spi device is disabled fast * The critical section here ensures that the spi device is disabled fast
* enough during a pixel is transmitted. * enough during a pixel is transmitted.
*/ */
@@ -541,9 +540,10 @@ static uint16_t stm32_ili93414ws_recvword(void)
/* Enable spi device followed by disable the spi device. /* Enable spi device followed by disable the spi device.
* *
* Ensure that the spi is disabled within 8 or 16 spi clock cycles depending * Ensure that the spi is disabled within 8 or 16 spi clock cycles
* on the configured spi bit mode. This is necessary to prevent that the next * depending on the configured spi bit mode. This is necessary to prevent
* data word is transmitted by the slave before the RX buffer is cleared. * that the next data word is transmitted by the slave before the RX
* buffer is cleared.
* Otherwise the RX buffer will be overwritten. * Otherwise the RX buffer will be overwritten.
* *
* Physically the spi clock is disabled after the current 8/16 clock cycles * Physically the spi clock is disabled after the current 8/16 clock cycles
@@ -562,12 +562,13 @@ static uint16_t stm32_ili93414ws_recvword(void)
leave_critical_section(flags); leave_critical_section(flags);
/* Waits until the RX buffer is filled with the received data word signalized /* Waits until the RX buffer is filled with the received data word
* by the spi hardware through the RXNE flag. * signalized by the spi hardware through the RXNE flag.
* A busy loop is preferred against interrupt driven receiving method here * A busy loop is preferred against interrupt driven receiving method here
* because this happened fairly often. Also we have to ensure to avoid a big * because this happened fairly often. Also we have to ensure to avoid a
* lock if the lcd driver doesn't send data anymore. * big lock if the lcd driver doesn't send data anymore.
* A latency of CPU clock / SPI clock * 16 SPI clocks should be enough here. * A latency of CPU clock / SPI clock * 16 SPI clocks should be enough
* here.
*/ */
for (n = 0; n < ILI93414WS_RECV_CLK * 16; n++) for (n = 0; n < ILI93414WS_RECV_CLK * 16; n++)
@@ -634,9 +635,11 @@ static int stm32_ili93414ws_recvblock(FAR struct ili93414ws_lcd_s *lcd,
/* Discard the first 8 bit dummy */ /* Discard the first 8 bit dummy */
/* 00000000 RRRRRR00 */ /* 00000000 RRRRRR00 */
w1 = stm32_ili93414ws_recvword(); w1 = stm32_ili93414ws_recvword();
/* GGGGGG00 BBBBBB00 */ /* GGGGGG00 BBBBBB00 */
w2 = stm32_ili93414ws_recvword(); w2 = stm32_ili93414ws_recvword();
*dest++ = (((w1 << 8) & 0xf800) | *dest++ = (((w1 << 8) & 0xf800) |
@@ -696,7 +699,10 @@ static int stm32_ili93414ws_recvblock(FAR struct ili93414ws_lcd_s *lcd,
while (nwords--) while (nwords--)
{ {
uint8_t r, g, b; uint8_t r;
uint8_t g;
uint8_t b;
r = (uint8_t)(stm32_ili93414ws_recvword() >> 3); r = (uint8_t)(stm32_ili93414ws_recvword() >> 3);
g = (uint8_t)(stm32_ili93414ws_recvword() >> 2); g = (uint8_t)(stm32_ili93414ws_recvword() >> 2);
b = (uint8_t)(stm32_ili93414ws_recvword() >> 3); b = (uint8_t)(stm32_ili93414ws_recvword() >> 3);
@@ -708,7 +714,7 @@ static int stm32_ili93414ws_recvblock(FAR struct ili93414ws_lcd_s *lcd,
{ {
/* 8-bit mode */ /* 8-bit mode */
uint8_t *dest = (uint8_t*)wd; uint8_t *dest = (uint8_t *)wd;
while (nwords--) while (nwords--)
{ {
@@ -792,19 +798,18 @@ static void stm32_ili93414ws_spiconfig(FAR struct ili9341_lcd_s *lcd)
FAR struct ili93414ws_lcd_s *priv = (FAR struct ili93414ws_lcd_s *)lcd; FAR struct ili93414ws_lcd_s *priv = (FAR struct ili93414ws_lcd_s *)lcd;
irqstate_t flags; irqstate_t flags;
uint16_t clrbitscr1 = SPI_CR1_CPHA|SPI_CR1_CPOL|SPI_CR1_BR_MASK| uint16_t clrbitscr1 = SPI_CR1_CPHA | SPI_CR1_CPOL | SPI_CR1_BR_MASK |
SPI_CR1_CRCEN|SPI_CR1_LSBFIRST|SPI_CR1_RXONLY| SPI_CR1_CRCEN | SPI_CR1_LSBFIRST | SPI_CR1_RXONLY |
SPI_CR1_DFF; SPI_CR1_DFF;
uint16_t setbitscr1 = SPI_CR1_BIDIOE|SPI_CR1_BIDIMODE|SPI_CR1_MSTR| uint16_t setbitscr1 = SPI_CR1_BIDIOE | SPI_CR1_BIDIMODE | SPI_CR1_MSTR |
SPI_CR1_SSI|SPI_CR1_SSM|ILI93414WS_SPI_BR; SPI_CR1_SSI | SPI_CR1_SSM | ILI93414WS_SPI_BR;
uint16_t clrbitscr2 = SPI_CR2_TXEIE|SPI_CR2_RXNEIE|SPI_CR2_ERRIE| uint16_t clrbitscr2 = SPI_CR2_TXEIE | SPI_CR2_RXNEIE | SPI_CR2_ERRIE |
SPI_CR2_FRF|SPI_CR2_SSOE; SPI_CR2_FRF | SPI_CR2_SSOE;
uint16_t setbitscr2 = 0; uint16_t setbitscr2 = 0;
flags = enter_critical_section(); flags = enter_critical_section();
/* Disable spi */ /* Disable spi */
@@ -817,8 +822,8 @@ static void stm32_ili93414ws_spiconfig(FAR struct ili9341_lcd_s *lcd)
#ifdef ILI93414WS_SPI #ifdef ILI93414WS_SPI
/* Backup cr1 and cr2 register to be sure they will be usable /* Backup cr1 and cr2 register to be sure they will be usable
* by default spi interface. Disable spi device here is necessary at the time * by default spi interface. Disable spi device here is necessary at the
* restoring the register during deselection. * time restoring the register during deselection.
*/ */
priv->cr2 = getreg16(ILI93414WS_SPI_CR2); priv->cr2 = getreg16(ILI93414WS_SPI_CR2);
@@ -887,7 +892,8 @@ static inline void stm32_ili93414ws_cmddata(
* *
****************************************************************************/ ****************************************************************************/
static int stm32_ili93414ws_backlight(FAR struct ili9341_lcd_s *lcd, int level) static int stm32_ili93414ws_backlight(FAR struct ili9341_lcd_s *lcd,
int level)
{ {
return OK; return OK;
} }
@@ -1104,7 +1110,7 @@ static int stm32_ili93414ws_recvparam(FAR struct ili9341_lcd_s *lcd,
#endif #endif
lcdinfo("param=%04x\n", param); lcdinfo("param=%04x\n", param);
return stm32_ili93414ws_recvblock(priv, (uint16_t*)param, 1); return stm32_ili93414ws_recvblock(priv, (uint16_t *)param, 1);
} }
/**************************************************************************** /****************************************************************************
@@ -1147,8 +1153,8 @@ static int stm32_ili93414ws_recvgram(FAR struct ili9341_lcd_s *lcd,
* *
* Returned Value: * Returned Value:
* On success, this function returns a reference to the LCD control object * On success, this function returns a reference to the LCD control object
* for the specified ILI9341 LCD Single chip driver connected as 4 wire serial * for the specified ILI9341 LCD Single chip driver connected as 4 wire
* (spi). NULL is returned on any failure. * serial (spi). NULL is returned on any failure.
* *
****************************************************************************/ ****************************************************************************/
@@ -1194,7 +1200,7 @@ FAR struct ili9341_lcd_s *stm32_ili93414ws_initialize(void)
/* Enable spi bus */ /* Enable spi bus */
regval= getreg32(STM32_RCC_APB2ENR); regval = getreg32(STM32_RCC_APB2ENR);
regval |= RCC_APB2ENR_SPI5EN; regval |= RCC_APB2ENR_SPI5EN;
putreg32(regval, STM32_RCC_APB2ENR); putreg32(regval, STM32_RCC_APB2ENR);
@@ -1217,7 +1223,6 @@ FAR struct ili9341_lcd_s *stm32_ili93414ws_initialize(void)
priv->dev.recvgram = stm32_ili93414ws_recvgram; priv->dev.recvgram = stm32_ili93414ws_recvgram;
priv->dev.backlight = stm32_ili93414ws_backlight; priv->dev.backlight = stm32_ili93414ws_backlight;
/* Configure to bidirectional transfer mode */ /* Configure to bidirectional transfer mode */
lcdinfo("Configure spi device %d to bidirectional transfer mode\n", lcdinfo("Configure spi device %d to bidirectional transfer mode\n",