From 3ea83706512a5051a185ac8ec4ba0094290a217d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 28 Oct 2010 18:39:40 +0000 Subject: LPC13xx SPI driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2300 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARMCM3-LPC1343-GCC/halconf.h | 2 +- demos/ARMCM3-LPC1343-GCC/main.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'demos/ARMCM3-LPC1343-GCC') 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 @@ -21,18 +21,50 @@ #include "hal.h" #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. -- cgit v1.2.3