Add reset_button.c and test_led.c. Clean up init_peripherials.c
This commit is contained in:
@@ -73,6 +73,7 @@
|
|||||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.336878990" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.336878990" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value="../../.."/>
|
<listOptionValue builtIn="false" value="../../.."/>
|
||||||
<listOptionValue builtIn="false" value="../../../src"/>
|
<listOptionValue builtIn="false" value="../../../src"/>
|
||||||
|
<listOptionValue builtIn="false" value="../../../src/ksdk_usb"/>
|
||||||
<listOptionValue builtIn="false" value="../../../src/usb_descriptors"/>
|
<listOptionValue builtIn="false" value="../../../src/usb_descriptors"/>
|
||||||
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/middleware/usb_1.0.0"/>
|
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/middleware/usb_1.0.0"/>
|
||||||
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/middleware/usb_1.0.0/osa"/>
|
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/middleware/usb_1.0.0/osa"/>
|
||||||
@@ -81,8 +82,7 @@
|
|||||||
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/CMSIS/Include"/>
|
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/CMSIS/Include"/>
|
||||||
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/devices/MK22F51212/drivers"/>
|
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/devices/MK22F51212/drivers"/>
|
||||||
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/devices/MK22F51212"/>
|
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_FRDM-K22F/devices/MK22F51212"/>
|
||||||
<listOptionValue builtIn="false" value="../../../../include"/>
|
<listOptionValue builtIn="false" value="../../../../shared"/>
|
||||||
<listOptionValue builtIn="false" value="../../../src/ksdk_usb"/>
|
|
||||||
</option>
|
</option>
|
||||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std.933718024" name="Language standard" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std.gnu99" valueType="enumerated"/>
|
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std.933718024" name="Language standard" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std.gnu99" valueType="enumerated"/>
|
||||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs.62587551" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs" useByScannerDiscovery="false" valueType="definedSymbols">
|
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs.62587551" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs" useByScannerDiscovery="false" valueType="definedSymbols">
|
||||||
|
|||||||
@@ -1,10 +1,29 @@
|
|||||||
#ifndef __MAIN_H__
|
#ifndef __I2C_H__
|
||||||
#define __MAIN_H__
|
#define __I2C_H__
|
||||||
|
|
||||||
#define I2C_BASEADDR_MAIN_BUS I2C0
|
#define I2C_MAIN_BUS_SDA_PORT PORTD
|
||||||
#define I2C_BASEADDR_EEPROM_BUS I2C1
|
#define I2C_MAIN_BUS_SDA_CLOCK kCLOCK_PortD
|
||||||
|
#define I2C_MAIN_BUS_SDA_PIN 3
|
||||||
|
|
||||||
#define I2C_BAUD_RATE 100000
|
#define I2C_MAIN_BUS_SCL_PORT PORTD
|
||||||
#define I2C_MASTER_CLK_SRC I2C0_CLK_SRC
|
#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
|
#endif
|
||||||
|
|||||||
@@ -5,42 +5,35 @@
|
|||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "led_driver.h"
|
#include "led_driver.h"
|
||||||
|
|
||||||
void InitPeripherials(void)
|
void InitI2c() {
|
||||||
{
|
port_pin_config_t pinConfig = {
|
||||||
// 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 = {
|
|
||||||
.pullSelect = kPORT_PullUp,
|
.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);
|
PORT_SetPinConfig(I2C_MAIN_BUS_SDA_PORT, I2C_MAIN_BUS_SDA_PIN, &pinConfig);
|
||||||
TEST_LED_INIT(0);
|
PORT_SetPinConfig(I2C_MAIN_BUS_SCL_PORT, I2C_MAIN_BUS_SCL_PIN, &pinConfig);
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
i2c_master_config_t masterConfig;
|
i2c_master_config_t masterConfig;
|
||||||
uint32_t sourceClock;
|
|
||||||
I2C_MasterGetDefaultConfig(&masterConfig);
|
I2C_MasterGetDefaultConfig(&masterConfig);
|
||||||
masterConfig.baudRate_Bps = I2C_BAUD_RATE;
|
|
||||||
sourceClock = CLOCK_GetFreq(I2C_MASTER_CLK_SRC);
|
masterConfig.baudRate_Bps = I2C_MAIN_BUS_BAUD_RATE;
|
||||||
I2C_MasterInit(I2C_BASEADDR_MAIN_BUS, &masterConfig, sourceClock);
|
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.data = buffer;
|
||||||
masterXfer.dataSize = size;
|
masterXfer.dataSize = size;
|
||||||
masterXfer.flags = kI2C_TransferDefaultFlag;
|
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)
|
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_GPIO GPIOB
|
||||||
#define RESET_BUTTON_PORT PORTB
|
#define RESET_BUTTON_PORT PORTB
|
||||||
|
#define RESET_BUTTON_CLOCK kCLOCK_PortB
|
||||||
#define RESET_BUTTON_PIN 1
|
#define RESET_BUTTON_PIN 1
|
||||||
#define RESET_BUTTON_IRQ PORTB_IRQn
|
#define RESET_BUTTON_IRQ PORTB_IRQn
|
||||||
#define RESET_BUTTON_IRQ_HANDLER PORTB_IRQHandler
|
#define RESET_BUTTON_IRQ_HANDLER PORTB_IRQHandler
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
extern void InitResetButton();
|
||||||
|
|
||||||
#endif
|
#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 GPIOD
|
||||||
#define TEST_LED_GPIO_PORT PORTD
|
#define TEST_LED_GPIO_PORT PORTD
|
||||||
|
#define TEST_LED_CLOCK kCLOCK_PortD
|
||||||
#define TEST_LED_GPIO_PIN 7U
|
#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_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_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)
|
#define TEST_LED_TOGGLE() GPIO_TogglePinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN)
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
extern void InitTestLed();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user