Add reset_button.c and test_led.c. Clean up init_peripherials.c
This commit is contained in:
@@ -1,10 +1,29 @@
|
||||
#ifndef __MAIN_H__
|
||||
#define __MAIN_H__
|
||||
#ifndef __I2C_H__
|
||||
#define __I2C_H__
|
||||
|
||||
#define I2C_BASEADDR_MAIN_BUS I2C0
|
||||
#define I2C_BASEADDR_EEPROM_BUS I2C1
|
||||
#define I2C_MAIN_BUS_SDA_PORT PORTD
|
||||
#define I2C_MAIN_BUS_SDA_CLOCK kCLOCK_PortD
|
||||
#define I2C_MAIN_BUS_SDA_PIN 3
|
||||
|
||||
#define I2C_BAUD_RATE 100000
|
||||
#define I2C_MASTER_CLK_SRC I2C0_CLK_SRC
|
||||
#define I2C_MAIN_BUS_SCL_PORT PORTD
|
||||
#define I2C_MAIN_BUS_SCL_CLOCK kCLOCK_PortD
|
||||
#define I2C_MAIN_BUS_SCL_PIN 2
|
||||
|
||||
#define I2C_EEPROM_BUS_SDA_PORT PORTC
|
||||
#define I2C_EEPROM_BUS_SDA_CLOCK kCLOCK_PortC
|
||||
#define I2C_EEPROM_BUS_SDA_PIN 11
|
||||
|
||||
#define I2C_EEPROM_BUS_SCL_PORT PORTC
|
||||
#define I2C_EEPROM_BUS_SCL_CLOCK kCLOCK_PortD
|
||||
#define I2C_EEPROM_BUS_SCL_PIN 10
|
||||
|
||||
#define I2C_MAIN_BUS_BASEADDR I2C0
|
||||
#define I2C_EEPROM_BUS_BASEADDR I2C1
|
||||
|
||||
#define I2C_MAIN_BUS_BAUD_RATE 100000
|
||||
#define I2C_EEPROM_BUS_BAUD_RATE 1000000
|
||||
|
||||
#define I2C_MASTER_BUS_CLK_SRC I2C0_CLK_SRC
|
||||
#define I2C_EEPROM_BUS_CLK_SRC I2C1_CLK_SRC
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,42 +5,35 @@
|
||||
#include "i2c.h"
|
||||
#include "led_driver.h"
|
||||
|
||||
void InitPeripherials(void)
|
||||
{
|
||||
// Ungate ports.
|
||||
CLOCK_EnableClock(kCLOCK_PortA); // LEDs
|
||||
CLOCK_EnableClock(kCLOCK_PortB); // SW3
|
||||
CLOCK_EnableClock(kCLOCK_PortC); // SW2
|
||||
CLOCK_EnableClock(kCLOCK_PortD); // LEDs, I2C
|
||||
|
||||
// Set up switches
|
||||
port_pin_config_t switchConfig = {
|
||||
void InitI2c() {
|
||||
port_pin_config_t pinConfig = {
|
||||
.pullSelect = kPORT_PullUp,
|
||||
.mux = kPORT_MuxAsGpio,
|
||||
.openDrainEnable = kPORT_OpenDrainEnable,
|
||||
.mux = kPORT_MuxAlt7
|
||||
};
|
||||
PORT_SetPinConfig(RESET_BUTTON_PORT, RESET_BUTTON_PIN, &switchConfig);
|
||||
|
||||
// Initialize LEDs.
|
||||
CLOCK_EnableClock(I2C_MAIN_BUS_SDA_CLOCK);
|
||||
CLOCK_EnableClock(I2C_MAIN_BUS_SCL_CLOCK);
|
||||
|
||||
PORT_SetPinMux(TEST_LED_GPIO_PORT, TEST_LED_GPIO_PIN, kPORT_MuxAsGpio);
|
||||
TEST_LED_INIT(0);
|
||||
|
||||
// Initialize I2C.
|
||||
|
||||
port_pin_config_t pinConfig = {0};
|
||||
pinConfig.pullSelect = kPORT_PullUp;
|
||||
pinConfig.openDrainEnable = kPORT_OpenDrainEnable;
|
||||
|
||||
PORT_SetPinConfig(PORTD, 2, &pinConfig);
|
||||
PORT_SetPinConfig(PORTD, 3, &pinConfig);
|
||||
|
||||
PORT_SetPinMux(PORTD, 2, kPORT_MuxAlt7);
|
||||
PORT_SetPinMux(PORTD, 3, kPORT_MuxAlt7);
|
||||
PORT_SetPinConfig(I2C_MAIN_BUS_SDA_PORT, I2C_MAIN_BUS_SDA_PIN, &pinConfig);
|
||||
PORT_SetPinConfig(I2C_MAIN_BUS_SCL_PORT, I2C_MAIN_BUS_SCL_PIN, &pinConfig);
|
||||
|
||||
i2c_master_config_t masterConfig;
|
||||
uint32_t sourceClock;
|
||||
I2C_MasterGetDefaultConfig(&masterConfig);
|
||||
masterConfig.baudRate_Bps = I2C_BAUD_RATE;
|
||||
sourceClock = CLOCK_GetFreq(I2C_MASTER_CLK_SRC);
|
||||
I2C_MasterInit(I2C_BASEADDR_MAIN_BUS, &masterConfig, sourceClock);
|
||||
|
||||
masterConfig.baudRate_Bps = I2C_MAIN_BUS_BAUD_RATE;
|
||||
uint32_t sourceClock = CLOCK_GetFreq(I2C_MASTER_BUS_CLK_SRC);
|
||||
I2C_MasterInit(I2C_MAIN_BUS_BASEADDR, &masterConfig, sourceClock);
|
||||
}
|
||||
|
||||
void InitPeripherials(void)
|
||||
{
|
||||
CLOCK_EnableClock(kCLOCK_PortA);
|
||||
CLOCK_EnableClock(kCLOCK_PortB);
|
||||
CLOCK_EnableClock(kCLOCK_PortC);
|
||||
CLOCK_EnableClock(kCLOCK_PortD);
|
||||
|
||||
InitResetButton();
|
||||
InitTestLed();
|
||||
InitI2c();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ void LedDriver_WriteBuffer(uint8_t i2cAddress, uint8_t buffer[], uint8_t size)
|
||||
masterXfer.data = buffer;
|
||||
masterXfer.dataSize = size;
|
||||
masterXfer.flags = kI2C_TransferDefaultFlag;
|
||||
I2C_MasterTransferBlocking(I2C_BASEADDR_MAIN_BUS, &masterXfer);
|
||||
I2C_MasterTransferBlocking(I2C_MAIN_BUS_BASEADDR, &masterXfer);
|
||||
}
|
||||
|
||||
void LedDriver_WriteRegister(uint8_t i2cAddress, uint8_t reg, uint8_t val)
|
||||
|
||||
8
right/src/reset_button.c
Normal file
8
right/src/reset_button.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "reset_button.h"
|
||||
#include "fsl_port.h"
|
||||
|
||||
void InitResetButton() {
|
||||
PORT_SetPinConfig(RESET_BUTTON_PORT, RESET_BUTTON_PIN,
|
||||
&(port_pin_config_t){.pullSelect=kPORT_PullUp, .mux=kPORT_MuxAsGpio});
|
||||
CLOCK_EnableClock(RESET_BUTTON_CLOCK);
|
||||
}
|
||||
@@ -9,8 +9,13 @@
|
||||
|
||||
#define RESET_BUTTON_GPIO GPIOB
|
||||
#define RESET_BUTTON_PORT PORTB
|
||||
#define RESET_BUTTON_CLOCK kCLOCK_PortB
|
||||
#define RESET_BUTTON_PIN 1
|
||||
#define RESET_BUTTON_IRQ PORTB_IRQn
|
||||
#define RESET_BUTTON_IRQ_HANDLER PORTB_IRQHandler
|
||||
|
||||
// Functions:
|
||||
|
||||
extern void InitResetButton();
|
||||
|
||||
#endif
|
||||
|
||||
9
right/src/test_led.c
Normal file
9
right/src/test_led.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "test_led.h"
|
||||
#include "fsl_port.h"
|
||||
|
||||
extern void InitTestLed()
|
||||
{
|
||||
PORT_SetPinMux(TEST_LED_GPIO_PORT, TEST_LED_GPIO_PIN, kPORT_MuxAsGpio);
|
||||
GPIO_PinInit(TEST_LED_GPIO, TEST_LED_GPIO_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 0});
|
||||
CLOCK_EnableClock(TEST_LED_CLOCK);
|
||||
}
|
||||
@@ -12,12 +12,15 @@
|
||||
|
||||
#define TEST_LED_GPIO GPIOD
|
||||
#define TEST_LED_GPIO_PORT PORTD
|
||||
#define TEST_LED_CLOCK kCLOCK_PortD
|
||||
#define TEST_LED_GPIO_PIN 7U
|
||||
|
||||
#define TEST_LED_INIT(output) GPIO_PinInit(TEST_LED_GPIO, TEST_LED_GPIO_PIN, \
|
||||
&(gpio_pin_config_t){kGPIO_DigitalOutput, (output)})
|
||||
#define TEST_LED_ON() GPIO_ClearPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN)
|
||||
#define TEST_LED_OFF() GPIO_SetPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN)
|
||||
#define TEST_LED_TOGGLE() GPIO_TogglePinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN)
|
||||
|
||||
// Functions:
|
||||
|
||||
extern void InitTestLed();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user