diff options
author | David Barksdale <amatus@amatus.name> | 2015-10-26 23:35:48 -0500 |
---|---|---|
committer | David Barksdale <amatus@amatus.name> | 2015-10-26 23:35:48 -0500 |
commit | 4c22f6308756334d9056feaa47817cb5ea71fd7c (patch) | |
tree | 18dc29eb1a551cbff54cd11b41bd183873b47b27 /laser-tag software | |
parent | 4ac8a23e01a028a7062e404e1c53c9b184d6e503 (diff) |
Changes to get the LCD working
Diffstat (limited to 'laser-tag software')
-rwxr-xr-x | laser-tag software/CMakeLists.txt | 1 | ||||
-rwxr-xr-x | laser-tag software/main.c | 65 |
2 files changed, 60 insertions, 6 deletions
diff --git a/laser-tag software/CMakeLists.txt b/laser-tag software/CMakeLists.txt index f04d332..26be541 100755 --- a/laser-tag software/CMakeLists.txt +++ b/laser-tag software/CMakeLists.txt @@ -94,6 +94,7 @@ ADD_EXECUTABLE(hello_world "${ProjDirPath}/../KSDK_1.2.0/platform/devices/startup.c"
"${ProjDirPath}/../KSDK_1.2.0/platform/devices/startup.h"
"${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/lpuart/fsl_lpuart_irq.c"
+ "${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/spi/fsl_spi_irq.c"
"${ProjDirPath}/main.c"
"${ProjDirPath}/fsl_lptmr_irq.c"
)
diff --git a/laser-tag software/main.c b/laser-tag software/main.c index 60098c5..0001608 100755 --- a/laser-tag software/main.c +++ b/laser-tag software/main.c @@ -39,6 +39,7 @@ #include "fsl_os_abstraction.h" #include "fsl_pit_driver.h" #include "fsl_smc_hal.h" +#include "fsl_spi_master_driver.h" //////////////////////////// @@ -102,15 +103,23 @@ static const smc_power_mode_config_t g_idlePowerMode = { /* LCD backlight GPIO pin */ static const gpio_output_pin_user_config_t g_lcdBacklight = { - .pinName = GPIO_MAKE_PIN(GPIOE_IDX, 31U), + .pinName = GPIO_MAKE_PIN(GPIOE_IDX, 31), .config.outputLogic = 1, .config.slewRate = kPortSlowSlewRate, .config.driveStrength = kPortLowDriveStrength, }; +/* LCD A0 GPIO pin */ +static const gpio_output_pin_user_config_t g_lcdA0 = { + .pinName = GPIO_MAKE_PIN(GPIOD_IDX, 6), + .config.outputLogic = 0, + .config.slewRate = kPortSlowSlewRate, + .config.driveStrength = kPortLowDriveStrength, +}; + /* Switch1 GPIO pin */ static const gpio_input_pin_user_config_t g_switch1 = { - .pinName = GPIO_MAKE_PIN(GPIOA_IDX, 1U), + .pinName = GPIO_MAKE_PIN(GPIOA_IDX, 1), .config.isPullEnable = true, .config.pullSelect = kPortPullUp, .config.interrupt = kPortIntEitherEdge, @@ -162,6 +171,14 @@ static lpuart_user_config_t g_lpuartConfig = { .bitCountPerChar = kLpuart9BitsPerChar, }; +/* LCD SPI config */ +static spi_master_user_config_t g_spi1Config = { + .bitsPerSec = 100000, // 100 kbps + .polarity = kSpiClockPolarity_ActiveLow, + .phase = kSpiClockPhase_SecondEdge, + .direction = kSpiMsbFirst, + .bitCount = kSpi8BitMode, +}; /////// // Code @@ -170,6 +187,7 @@ static cmp_state_t g_cmpState; static dma_channel_t g_chan; static lpuart_state_t g_lpuartState; static uint8_t rxBuff[1]; +static spi_master_state_t g_spi1State; /*! * @brief LPTMR interrupt call back function. @@ -225,8 +243,11 @@ static void lpuartRxCallback(uint32_t instance, void *lpuartState) int main (void) { /* enable clock for PORTs */ - //CLOCK_SYS_EnablePortClock(PORTA_IDX); + CLOCK_SYS_EnablePortClock(PORTA_IDX); + //CLOCK_SYS_EnablePortClock(PORTB_IDX); //CLOCK_SYS_EnablePortClock(PORTC_IDX); + CLOCK_SYS_EnablePortClock(PORTD_IDX); + CLOCK_SYS_EnablePortClock(PORTE_IDX); /* Set allowed power mode, allow all. */ SMC_HAL_SetProtection(SMC, kAllowPowerModeAll); @@ -240,9 +261,6 @@ int main (void) LPTMR_DRV_SetTimerPeriodUs(LPTMR0_IDX, 100000); LPTMR_DRV_InstallCallback(LPTMR0_IDX, lptmr_call_back); - /* Initialize LCD backlight LED GPIO */ - GPIO_DRV_OutputPinInit(&g_lcdBacklight); - /* Initialize PIT */ PIT_DRV_Init(0, false); PIT_DRV_InitChannel(0, 0, &g_pitChan0); @@ -292,6 +310,41 @@ int main (void) LPUART_DRV_InstallRxCallback(1, lpuartRxCallback, rxBuff, NULL, true); PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 1, kPortMuxAlt3); + /* Setup LCD */ + GPIO_DRV_OutputPinInit(&g_lcdBacklight); + GPIO_DRV_OutputPinInit(&g_lcdA0); + PORT_HAL_SetMuxMode(g_portBase[GPIOD_IDX], 4, kPortMuxAlt2); // CS + PORT_HAL_SetMuxMode(g_portBase[GPIOD_IDX], 5, kPortMuxAlt2); // SCL + PORT_HAL_SetMuxMode(g_portBase[GPIOD_IDX], 7, kPortMuxAlt5); // SI + SPI_DRV_MasterInit(1, &g_spi1State); + uint32_t baud; + SPI_DRV_MasterConfigureBus(1, &g_spi1Config, &baud); + uint8_t buff[] = { + 0x80, 0x21, // Set electronic "volume" to 33/63 + 0x2f, // Set power control: booster on, regulator on, follower on + 0xaf, // Display ON + 0x40, // Set display line start address to 0 + //0xa5, // all points ON + }; + SPI_DRV_MasterTransferBlocking(1, NULL, buff, NULL, sizeof(buff), 1000); + + // Try to write something to the display + int i; + for (i = 0; i < 4; ++i) { + int j; + uint8_t buff[] = { + 0xb + i, // Set page address to i + 0x00, 0x10 // Set column address to 0 + }; + GPIO_DRV_ClearPinOutput(g_lcdA0.pinName); + SPI_DRV_MasterTransferBlocking(1, NULL, buff, NULL, sizeof(buff), 1000); + GPIO_DRV_SetPinOutput(g_lcdA0.pinName); + for (j = 0; j < 128; ++j) { + uint8_t byte = 0x33; + SPI_DRV_MasterTransferBlocking(1, NULL, &byte, NULL, 1, 1000); + } + } + /* We're done, everything else is triggered through interrupts */ for(;;) { #ifndef DEBUG |