From: Keith Packard Date: Thu, 7 Apr 2022 05:45:41 +0000 (-0700) Subject: lpc: Add SPI mode support. Use for ADXL375 on easymotor X-Git-Tag: 1.9.12~1^2~17^2~5 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=40a56ed2b5af30c93daa74a15f21e7c8b4cb2a1a lpc: Add SPI mode support. Use for ADXL375 on easymotor Signed-off-by: Keith Packard --- diff --git a/src/easymotor-v3/ao_pins.h b/src/easymotor-v3/ao_pins.h index 89d9db0e..2db8a422 100644 --- a/src/easymotor-v3/ao_pins.h +++ b/src/easymotor-v3/ao_pins.h @@ -126,11 +126,13 @@ struct ao_adc { /* SPI */ #define HAS_SPI_0 1 +#define SPI_0_MODE ((0 << LPC_SSP_CR0_CPOL) | (0 << LPC_SSP_CR0_CPHA)) #define SPI_SCK0_P0_6 1 #define HAS_SPI_1 1 #define SPI_SCK1_P1_15 1 #define SPI_MISO1_P0_22 1 #define SPI_MOSI1_P0_21 1 +#define SPI_1_MODE ((1 << LPC_SSP_CR0_CPOL) | (1 << LPC_SSP_CR0_CPHA)) /* * SPI Flash memory diff --git a/src/lpc/ao_spi_lpc.c b/src/lpc/ao_spi_lpc.c index ec48e95c..010feb63 100644 --- a/src/lpc/ao_spi_lpc.c +++ b/src/lpc/ao_spi_lpc.c @@ -90,7 +90,7 @@ ao_spi_put(uint8_t id) } static void -ao_spi_channel_init(uint8_t id) +ao_spi_channel_init(uint8_t id, uint8_t mode) { struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; uint8_t d; @@ -102,8 +102,7 @@ ao_spi_channel_init(uint8_t id) lpc_ssp->cr0 = ((LPC_SSP_CR0_DSS_8 << LPC_SSP_CR0_DSS) | (LPC_SSP_CR0_FRF_SPI << LPC_SSP_CR0_FRF) | - (0 << LPC_SSP_CR0_CPOL) | - (0 << LPC_SSP_CR0_CPHA) | + mode | (0 << LPC_SSP_CR0_SCR)); /* Enable the device */ @@ -121,6 +120,9 @@ void ao_spi_init(void) { #if HAS_SPI_0 +#ifndef SPI_0_MODE +#define SPI_0_MODE 0 +#endif /* Configure pins */ #if SPI_SCK0_P0_6 lpc_ioconf.pio0_6 = ao_lpc_alternate(LPC_IOCONF_FUNC_PIO0_6_SCK0); @@ -149,10 +151,13 @@ ao_spi_init(void) /* Reset the device */ lpc_scb.presetctrl &= ~(1UL << LPC_SCB_PRESETCTRL_SSP0_RST_N); lpc_scb.presetctrl |= (1 << LPC_SCB_PRESETCTRL_SSP0_RST_N); - ao_spi_channel_init(0); + ao_spi_channel_init(0, SPI_0_MODE); #endif #if HAS_SPI_1 +#ifndef SPI_1_MODE +#define SPI_1_MODE 0 +#endif #if SPI_SCK1_P1_15 lpc_ioconf.pio1_15 = ao_lpc_alternate(LPC_IOCONF_FUNC_PIO1_15_SCK1); @@ -199,6 +204,6 @@ ao_spi_init(void) /* Reset the device */ lpc_scb.presetctrl &= ~(1UL << LPC_SCB_PRESETCTRL_SSP1_RST_N); lpc_scb.presetctrl |= (1 << LPC_SCB_PRESETCTRL_SSP1_RST_N); - ao_spi_channel_init(1); + ao_spi_channel_init(1, SPI_1_MODE); #endif /* HAS_SPI_1 */ }