Extract LED driver related functions to led_driver.[ch]
This commit is contained in:
52
right/src/led_driver.c
Normal file
52
right/src/led_driver.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "led_driver.h"
|
||||
|
||||
void LedDriver_WriteBuffer(uint8_t txBuffer[], uint8_t size)
|
||||
{
|
||||
i2c_master_transfer_t masterXfer;
|
||||
masterXfer.slaveAddress = LEFT_LED_DRIVER_ADDRESS_7BIT;
|
||||
masterXfer.direction = kI2C_Write;
|
||||
masterXfer.subaddress = 0;
|
||||
masterXfer.subaddressSize = 0;
|
||||
masterXfer.data = txBuffer;
|
||||
masterXfer.dataSize = size;
|
||||
masterXfer.flags = kI2C_TransferDefaultFlag;
|
||||
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);
|
||||
masterXfer.slaveAddress = RIGHT_LED_DRIVER_ADDRESS_7BIT;
|
||||
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);
|
||||
}
|
||||
|
||||
void LedDriver_WriteRegister(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t txBuffer[] = {0, 0};
|
||||
txBuffer[0] = reg;
|
||||
txBuffer[1] = val;
|
||||
LedDriver_WriteBuffer(txBuffer, sizeof(txBuffer));
|
||||
}
|
||||
|
||||
void LedDriver_EnableAllLeds()
|
||||
{
|
||||
PORT_SetPinMux(PORTA, 2U, kPORT_MuxAsGpio);
|
||||
|
||||
gpio_pin_config_t led_config = {
|
||||
.pinDirection = kGPIO_DigitalOutput,
|
||||
.outputLogic = 0,
|
||||
};
|
||||
|
||||
GPIO_PinInit(GPIOA, 2U, &led_config);
|
||||
GPIO_SetPinsOutput(GPIOA, 0 << 2U);
|
||||
|
||||
LedDriver_WriteRegister(0xfd, 0x0b); // point to page 9
|
||||
LedDriver_WriteRegister(0x0a, 0x01); // set shutdown mode to normal
|
||||
LedDriver_WriteRegister(0xfd, 0x00); // point to page 0
|
||||
|
||||
uint8_t i;
|
||||
for (i=0x00; i<=0x11; i++) {
|
||||
LedDriver_WriteRegister(i, 0xff);
|
||||
}
|
||||
for (i=0x12; i<=0x23; i++) {
|
||||
LedDriver_WriteRegister(i, 0x00);
|
||||
}
|
||||
for (i=0x24; i<=0xb3; i++) {
|
||||
LedDriver_WriteRegister(i, 0xff);
|
||||
}
|
||||
}
|
||||
19
right/src/led_driver.h
Normal file
19
right/src/led_driver.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef __LED_DRIVER_H__
|
||||
#define __LED_DRIVER_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "fsl_gpio.h"
|
||||
#include "fsl_port.h"
|
||||
|
||||
#include "fsl_i2c.h"
|
||||
#include "i2c.h"
|
||||
#include "i2c_addresses.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
extern void LedDriver_WriteBuffer(uint8_t txBuffer[], uint8_t size);
|
||||
extern void LedDriver_WriteRegister(uint8_t reg, uint8_t val);
|
||||
extern void LedDriver_EnableAllLeds();
|
||||
|
||||
#endif
|
||||
@@ -4,61 +4,9 @@
|
||||
#include "include/board/pin_mux.h"
|
||||
#include "usb_composite_device.h"
|
||||
#include "i2c.h"
|
||||
#include "main.h"
|
||||
#include "fsl_common.h"
|
||||
#include "fsl_port.h"
|
||||
|
||||
void tx(uint8_t txBuffer[], uint8_t size)
|
||||
{
|
||||
i2c_master_transfer_t masterXfer;
|
||||
masterXfer.slaveAddress = LEFT_LED_DRIVER_ADDRESS_7BIT;
|
||||
masterXfer.direction = kI2C_Write;
|
||||
masterXfer.subaddress = 0;
|
||||
masterXfer.subaddressSize = 0;
|
||||
masterXfer.data = txBuffer;
|
||||
masterXfer.dataSize = size;
|
||||
masterXfer.flags = kI2C_TransferDefaultFlag;
|
||||
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);
|
||||
masterXfer.slaveAddress = RIGHT_LED_DRIVER_ADDRESS_7BIT;
|
||||
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);
|
||||
}
|
||||
|
||||
void write(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t txBuffer[] = {0, 0};
|
||||
txBuffer[0] = reg;
|
||||
txBuffer[1] = val;
|
||||
tx(txBuffer, sizeof(txBuffer));
|
||||
}
|
||||
|
||||
void InitLedDisplay()
|
||||
{
|
||||
PORT_SetPinMux(PORTA, 2U, kPORT_MuxAsGpio);
|
||||
|
||||
gpio_pin_config_t led_config = {
|
||||
.pinDirection = kGPIO_DigitalOutput,
|
||||
.outputLogic = 0,
|
||||
};
|
||||
|
||||
GPIO_PinInit(GPIOA, 2U, &led_config);
|
||||
GPIO_SetPinsOutput(GPIOA, 0 << 2U);
|
||||
|
||||
write(0xfd, 0x0b); // point to page 9
|
||||
write(0x0a, 0x01); // set shutdown mode to normal
|
||||
write(0xfd, 0x00); // point to page 0
|
||||
|
||||
uint8_t i;
|
||||
for (i=0x00; i<=0x11; i++) {
|
||||
write(i, 0xff);
|
||||
}
|
||||
for (i=0x12; i<=0x23; i++) {
|
||||
write(i, 0x00);
|
||||
}
|
||||
for (i=0x24; i<=0xb3; i++) {
|
||||
write(i, 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
BOARD_InitPins();
|
||||
BOARD_BootClockRUN();
|
||||
@@ -70,7 +18,7 @@ void main() {
|
||||
sourceClock = CLOCK_GetFreq(I2C_MASTER_CLK_SRC);
|
||||
I2C_MasterInit(EXAMPLE_I2C_MASTER_BASEADDR, &masterConfig, sourceClock);
|
||||
|
||||
InitLedDisplay();
|
||||
LedDriver_EnableAllLeds();
|
||||
InitUsb();
|
||||
|
||||
while (1);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "usb_interface_mouse.h"
|
||||
#include "fsl_i2c.h"
|
||||
#include "i2c.h"
|
||||
#include "main.h"
|
||||
|
||||
static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{
|
||||
USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
|
||||
Reference in New Issue
Block a user