LPC13xx SPI driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2300 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
29a259ba43
commit
3ea8370651
|
@ -130,7 +130,7 @@
|
||||||
* @brief Enables the SPI subsystem.
|
* @brief Enables the SPI subsystem.
|
||||||
*/
|
*/
|
||||||
#if !defined(CH_HAL_USE_SPI) || defined(__DOXYGEN__)
|
#if !defined(CH_HAL_USE_SPI) || defined(__DOXYGEN__)
|
||||||
#define CH_HAL_USE_SPI FALSE
|
#define CH_HAL_USE_SPI TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -21,18 +21,50 @@
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "test.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.
|
* Red LED blinker thread, times are in milliseconds.
|
||||||
*/
|
*/
|
||||||
static WORKING_AREA(waThread1, 128);
|
static WORKING_AREA(waThread1, 128);
|
||||||
static msg_t Thread1(void *arg) {
|
static msg_t Thread1(void *arg) {
|
||||||
|
uint8_t i = 0;
|
||||||
|
|
||||||
(void)arg;
|
(void)arg;
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
|
spiSelect(&SPID1);
|
||||||
|
spiStartSend(&SPID1, 1, &digits[i]);
|
||||||
palClearPad(GPIO0, GPIO0_LED2);
|
palClearPad(GPIO0, GPIO0_LED2);
|
||||||
chThdSleepMilliseconds(500);
|
chThdSleepMilliseconds(500);
|
||||||
|
spiSelect(&SPID1);
|
||||||
|
spiStartSend(&SPID1, 1, &digits[i | 0x10]);
|
||||||
palSetPad(GPIO0, GPIO0_LED2);
|
palSetPad(GPIO0, GPIO0_LED2);
|
||||||
chThdSleepMilliseconds(500);
|
chThdSleepMilliseconds(500);
|
||||||
|
i = (i + 1) & 15;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -78,9 +110,10 @@ int main(int argc, char **argv) {
|
||||||
(void)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.
|
* Creates the blinker threads.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# List of all the LPC13xx platform files.
|
# List of all the LPC13xx platform files.
|
||||||
PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/LPC13xx/hal_lld.c \
|
PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/LPC13xx/hal_lld.c \
|
||||||
${CHIBIOS}/os/hal/platforms/LPC13xx/pal_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
|
${CHIBIOS}/os/hal/platforms/LPC13xx/spi_lld.c
|
||||||
|
|
||||||
# Required include directories
|
# Required include directories
|
||||||
|
|
|
@ -214,7 +214,7 @@ static void notify1(void) {
|
||||||
* @isr
|
* @isr
|
||||||
*/
|
*/
|
||||||
#if LPC13xx_SERIAL_USE_UART0 || defined(__DOXYGEN__)
|
#if LPC13xx_SERIAL_USE_UART0 || defined(__DOXYGEN__)
|
||||||
CH_IRQ_HANDLER(Vector94) {
|
CH_IRQ_HANDLER(VectorF8) {
|
||||||
|
|
||||||
CH_IRQ_PROLOGUE();
|
CH_IRQ_PROLOGUE();
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ static void spi_serve_interrupt(SPIDriver *spip) {
|
||||||
*
|
*
|
||||||
* @isr
|
* @isr
|
||||||
*/
|
*/
|
||||||
CH_IRQ_HANDLER(Vector90) {
|
CH_IRQ_HANDLER(VectorF4) {
|
||||||
|
|
||||||
CH_IRQ_PROLOGUE();
|
CH_IRQ_PROLOGUE();
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ void spi_lld_init(void) {
|
||||||
|
|
||||||
#if LPC13xx_SPI_USE_SSP0
|
#if LPC13xx_SPI_USE_SSP0
|
||||||
spiObjectInit(&SPID1);
|
spiObjectInit(&SPID1);
|
||||||
SPID1.spd_ssp = LPC_SSP0;
|
SPID1.spd_ssp = LPC_SSP;
|
||||||
LPC_IOCON->SCK_LOC = LPC13xx_SPI_SCK0_SELECTOR;
|
LPC_IOCON->SCKLOC = LPC13xx_SPI_SCK0_SELECTOR;
|
||||||
#if LPC13xx_SPI_SCK0_SELECTOR == SCK0_IS_PIO0_10
|
#if LPC13xx_SPI_SCK0_SELECTOR == SCK0_IS_PIO0_10
|
||||||
LPC_IOCON->JTAG_TCK_PIO0_10 = 0xC2; /* SCK0 without resistors. */
|
LPC_IOCON->JTAG_TCK_PIO0_10 = 0xC2; /* SCK0 without resistors. */
|
||||||
#elif LPC13xx_SPI_SCK0_SELECTOR == SCK0_IS_PIO2_11
|
#elif LPC13xx_SPI_SCK0_SELECTOR == SCK0_IS_PIO2_11
|
||||||
|
@ -170,10 +170,10 @@ void spi_lld_start(SPIDriver *spip) {
|
||||||
/* Clock activation.*/
|
/* Clock activation.*/
|
||||||
#if LPC13xx_SPI_USE_SSP0
|
#if LPC13xx_SPI_USE_SSP0
|
||||||
if (&SPID1 == spip) {
|
if (&SPID1 == spip) {
|
||||||
LPC_SYSCON->SSP0CLKDIV = LPC13xx_SPI_SSP0CLKDIV;
|
LPC_SYSCON->SSPCLKDIV = LPC13xx_SPI_SSP0CLKDIV;
|
||||||
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11);
|
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11);
|
||||||
LPC_SYSCON->PRESETCTRL |= 1;
|
LPC_SYSCON->PRESETCTRL |= 1;
|
||||||
NVICEnableVector(SSP0_IRQn,
|
NVICEnableVector(SSP_IRQn,
|
||||||
CORTEX_PRIORITY_MASK(LPC13xx_SPI_SSP0_IRQ_PRIORITY));
|
CORTEX_PRIORITY_MASK(LPC13xx_SPI_SSP0_IRQ_PRIORITY));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -200,8 +200,8 @@ void spi_lld_stop(SPIDriver *spip) {
|
||||||
if (&SPID1 == spip) {
|
if (&SPID1 == spip) {
|
||||||
LPC_SYSCON->PRESETCTRL &= ~1;
|
LPC_SYSCON->PRESETCTRL &= ~1;
|
||||||
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 11);
|
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 11);
|
||||||
LPC_SYSCON->SSP0CLKDIV = 0;
|
LPC_SYSCON->SSPCLKDIV = 0;
|
||||||
NVICDisableVector(SSP0_IRQn);
|
NVICDisableVector(SSP_IRQn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue