diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-10-28 18:39:40 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-10-28 18:39:40 +0000 |
commit | 3ea83706512a5051a185ac8ec4ba0094290a217d (patch) | |
tree | f252f07fed2ccf821729d9ec595695b90fb58f65 | |
parent | 29a259ba43607142487a0bceb8adf31d76286770 (diff) | |
download | ChibiOS-3ea83706512a5051a185ac8ec4ba0094290a217d.tar.gz ChibiOS-3ea83706512a5051a185ac8ec4ba0094290a217d.tar.bz2 ChibiOS-3ea83706512a5051a185ac8ec4ba0094290a217d.zip |
LPC13xx SPI driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2300 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | demos/ARMCM3-LPC1343-GCC/halconf.h | 2 | ||||
-rw-r--r-- | demos/ARMCM3-LPC1343-GCC/main.c | 37 | ||||
-rw-r--r-- | os/hal/platforms/LPC13xx/platform.mk | 2 | ||||
-rw-r--r-- | os/hal/platforms/LPC13xx/serial_lld.c | 2 | ||||
-rw-r--r-- | os/hal/platforms/LPC13xx/spi_lld.c | 14 |
5 files changed, 45 insertions, 12 deletions
diff --git a/demos/ARMCM3-LPC1343-GCC/halconf.h b/demos/ARMCM3-LPC1343-GCC/halconf.h index 87d0f835d..2c3afda84 100644 --- a/demos/ARMCM3-LPC1343-GCC/halconf.h +++ b/demos/ARMCM3-LPC1343-GCC/halconf.h @@ -130,7 +130,7 @@ * @brief Enables the SPI subsystem.
*/
#if !defined(CH_HAL_USE_SPI) || defined(__DOXYGEN__)
-#define CH_HAL_USE_SPI FALSE
+#define CH_HAL_USE_SPI TRUE
#endif
/*
diff --git a/demos/ARMCM3-LPC1343-GCC/main.c b/demos/ARMCM3-LPC1343-GCC/main.c index 45496acfc..092cecdbb 100644 --- a/demos/ARMCM3-LPC1343-GCC/main.c +++ b/demos/ARMCM3-LPC1343-GCC/main.c @@ -22,17 +22,49 @@ #include "test.h"
/*
+ * Conversion table from hex digit to 7 segments encoding, bit 5 controls the
+ * dot.
+ * 8 = LU, 4 = RL, 2 = D, 1 = RU, 8 = U, 4 = M, 2 = LL, 1 = L.
+ */
+static uint8_t digits[32] = {
+ 0x24, 0xAF, 0xE0, 0xA2, 0x2B, 0x32, 0x30, 0xA7,
+ 0x20, 0x22, 0x21, 0x38, 0x74, 0xA8, 0x70, 0x71,
+ 0x04, 0x8F, 0xC0, 0x82, 0x0B, 0x12, 0x10, 0x87,
+ 0x00, 0x02, 0x01, 0x18, 0x54, 0x88, 0x50, 0x51
+};
+
+static void endsend(SPIDriver *spip) {
+
+ spiUnselect(spip);
+}
+
+/* Maximum speed SPI configuration (1MHz, CPHA=0, CPOL=0).*/
+static SPIConfig spicfg = {
+ endsend,
+ GPIO1,
+ GPIO1_SPI0SEL,
+ CR0_DSS8BIT | CR0_FRFSPI | CR0_CLOCKRATE(0),
+ 72
+};
+
+/*
* Red LED blinker thread, times are in milliseconds.
*/
static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {
+ uint8_t i = 0;
(void)arg;
while (TRUE) {
+ spiSelect(&SPID1);
+ spiStartSend(&SPID1, 1, &digits[i]);
palClearPad(GPIO0, GPIO0_LED2);
chThdSleepMilliseconds(500);
+ spiSelect(&SPID1);
+ spiStartSend(&SPID1, 1, &digits[i | 0x10]);
palSetPad(GPIO0, GPIO0_LED2);
chThdSleepMilliseconds(500);
+ i = (i + 1) & 15;
}
return 0;
}
@@ -78,9 +110,10 @@ int main(int argc, char **argv) { (void)argv;
/*
- * Activates the serial driver 1 using the driver default configuration.
+ * Activates the SD1 and SPI1 drivers.
*/
- sdStart(&SD1, NULL);
+ sdStart(&SD1, NULL); /* Default: 38400,8,N,1. */
+ spiStart(&SPID1, &spicfg);
/*
* Creates the blinker threads.
diff --git a/os/hal/platforms/LPC13xx/platform.mk b/os/hal/platforms/LPC13xx/platform.mk index 150e2126e..66c39058e 100644 --- a/os/hal/platforms/LPC13xx/platform.mk +++ b/os/hal/platforms/LPC13xx/platform.mk @@ -1,7 +1,7 @@ # List of all the LPC13xx platform files.
PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/LPC13xx/hal_lld.c \
${CHIBIOS}/os/hal/platforms/LPC13xx/pal_lld.c \
- ${CHIBIOS}/os/hal/platforms/LPC13xx/serial_lld.c
+ ${CHIBIOS}/os/hal/platforms/LPC13xx/serial_lld.c \
${CHIBIOS}/os/hal/platforms/LPC13xx/spi_lld.c
# Required include directories
diff --git a/os/hal/platforms/LPC13xx/serial_lld.c b/os/hal/platforms/LPC13xx/serial_lld.c index 1da872eac..2284a1646 100644 --- a/os/hal/platforms/LPC13xx/serial_lld.c +++ b/os/hal/platforms/LPC13xx/serial_lld.c @@ -214,7 +214,7 @@ static void notify1(void) { * @isr
*/
#if LPC13xx_SERIAL_USE_UART0 || defined(__DOXYGEN__)
-CH_IRQ_HANDLER(Vector94) {
+CH_IRQ_HANDLER(VectorF8) {
CH_IRQ_PROLOGUE();
diff --git a/os/hal/platforms/LPC13xx/spi_lld.c b/os/hal/platforms/LPC13xx/spi_lld.c index 299e394bd..d9b8ef06f 100644 --- a/os/hal/platforms/LPC13xx/spi_lld.c +++ b/os/hal/platforms/LPC13xx/spi_lld.c @@ -120,7 +120,7 @@ static void spi_serve_interrupt(SPIDriver *spip) { *
* @isr
*/
-CH_IRQ_HANDLER(Vector90) {
+CH_IRQ_HANDLER(VectorF4) {
CH_IRQ_PROLOGUE();
@@ -143,8 +143,8 @@ void spi_lld_init(void) { #if LPC13xx_SPI_USE_SSP0
spiObjectInit(&SPID1);
- SPID1.spd_ssp = LPC_SSP0;
- LPC_IOCON->SCK_LOC = LPC13xx_SPI_SCK0_SELECTOR;
+ SPID1.spd_ssp = LPC_SSP;
+ LPC_IOCON->SCKLOC = LPC13xx_SPI_SCK0_SELECTOR;
#if LPC13xx_SPI_SCK0_SELECTOR == SCK0_IS_PIO0_10
LPC_IOCON->JTAG_TCK_PIO0_10 = 0xC2; /* SCK0 without resistors. */
#elif LPC13xx_SPI_SCK0_SELECTOR == SCK0_IS_PIO2_11
@@ -170,10 +170,10 @@ void spi_lld_start(SPIDriver *spip) { /* Clock activation.*/
#if LPC13xx_SPI_USE_SSP0
if (&SPID1 == spip) {
- LPC_SYSCON->SSP0CLKDIV = LPC13xx_SPI_SSP0CLKDIV;
+ LPC_SYSCON->SSPCLKDIV = LPC13xx_SPI_SSP0CLKDIV;
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11);
LPC_SYSCON->PRESETCTRL |= 1;
- NVICEnableVector(SSP0_IRQn,
+ NVICEnableVector(SSP_IRQn,
CORTEX_PRIORITY_MASK(LPC13xx_SPI_SSP0_IRQ_PRIORITY));
}
#endif
@@ -200,8 +200,8 @@ void spi_lld_stop(SPIDriver *spip) { if (&SPID1 == spip) {
LPC_SYSCON->PRESETCTRL &= ~1;
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 11);
- LPC_SYSCON->SSP0CLKDIV = 0;
- NVICDisableVector(SSP0_IRQn);
+ LPC_SYSCON->SSPCLKDIV = 0;
+ NVICDisableVector(SSP_IRQn);
return;
}
#endif
|