mirror of
https://github.com/EranMorkon/AMTS.git
synced 2023-12-28 16:48:38 +00:00
Comments to source code
This commit is contained in:
parent
d109bae8d7
commit
9a18bd88f0
22 changed files with 286 additions and 122 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "rgb.h"
|
||||
#include "main.h"
|
||||
|
||||
// Define registers of the RGB LED driver
|
||||
typedef enum {
|
||||
RGB_SHUTDOWN = 0x00,
|
||||
RGB_MAXCUR,
|
||||
|
@ -15,14 +16,17 @@ typedef enum {
|
|||
|
||||
void rgb_send_command(uint8_t data)
|
||||
{
|
||||
// Generate start condition and transmit address
|
||||
I2C_GenerateSTART(I2C1, ENABLE);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
|
||||
I2C_Send7bitAddress(I2C1, RGB_ADDR, I2C_Direction_Transmitter);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
|
||||
|
||||
// Send data
|
||||
I2C_SendData(I2C1, data);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
|
||||
|
||||
// Generate stop condition
|
||||
I2C_GenerateSTOP(I2C1, ENABLE);
|
||||
|
||||
return;
|
||||
|
@ -30,36 +34,42 @@ void rgb_send_command(uint8_t data)
|
|||
|
||||
void init_rgb(void)
|
||||
{
|
||||
// Enable GPIOB anf I2C1 clocks
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
|
||||
// Create gpio struct and fill it with default values
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
// SCL
|
||||
// SET PB6 to alternate function push pull (SCL)
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_6;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
// SDA
|
||||
// Set PB7 to alternate function open drain (SDA)
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
gpio.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
// Init I2C1 to 400 kHz
|
||||
I2C_InitTypeDef i2c;
|
||||
I2C_StructInit(&i2c);
|
||||
i2c.I2C_ClockSpeed = 400000;
|
||||
I2C_Init(I2C1, &i2c);
|
||||
|
||||
// Enable I2C1 driver
|
||||
I2C_Cmd(I2C1, ENABLE);
|
||||
|
||||
// LED actually allows 40mA, but driver only hanbdles around 30
|
||||
// Set the max current the driver should allow
|
||||
// LED actually allows 40mA, but driver only handles around 30
|
||||
rgb_send_command(0x3F);
|
||||
return;
|
||||
}
|
||||
|
||||
void run_rgb(void)
|
||||
{
|
||||
// Set random colors for 100 ms each
|
||||
rgb_send_command(0x5F);
|
||||
wait(100);
|
||||
rgb_send_command(0x7F);
|
||||
|
@ -83,6 +93,7 @@ void run_rgb(void)
|
|||
|
||||
void deinit_rgb(void)
|
||||
{
|
||||
// Disable I2C1
|
||||
I2C_Cmd(I2C1, DISABLE);
|
||||
I2C_DeInit(I2C1);
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue