mirror of
https://github.com/EranMorkon/AMTS.git
synced 2023-12-28 16:48:38 +00:00
Software
This commit is contained in:
parent
4093cd295f
commit
dc99dcf6e8
41 changed files with 1775 additions and 19 deletions
83
Mieke/SW/MT/bma.c
Normal file
83
Mieke/SW/MT/bma.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
#include "bma.h"
|
||||
|
||||
void init_bma(void)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
// SCL
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_6;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
// SDA
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
gpio.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
I2C_InitTypeDef i2c;
|
||||
I2C_StructInit(&i2c);
|
||||
i2c.I2C_ClockSpeed = 400000;
|
||||
I2C_Init(I2C1, &i2c);
|
||||
|
||||
I2C_Cmd(I2C1, ENABLE);
|
||||
}
|
||||
|
||||
void run_bma(float acc_f[3])
|
||||
{
|
||||
int16_t acc[3];
|
||||
// Select first register address to read
|
||||
I2C_GenerateSTART(I2C1, ENABLE);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
|
||||
I2C_Send7bitAddress(I2C1, BMA_ADDR, I2C_Direction_Transmitter);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
|
||||
I2C_SendData(I2C1, 0x02);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
|
||||
I2C_GenerateSTOP(I2C1, ENABLE);
|
||||
|
||||
I2C_GenerateSTART(I2C1, ENABLE);
|
||||
I2C_AcknowledgeConfig(I2C1, ENABLE);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
|
||||
I2C_Send7bitAddress(I2C1, BMA_ADDR, I2C_Direction_Receiver);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
|
||||
|
||||
// X LSB
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
|
||||
acc[0] = (I2C_ReceiveData(I2C1) & 0xC0) >> 6;
|
||||
// X MSB
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
|
||||
acc[0] = (I2C_ReceiveData(I2C1) & 0xFF) << 2 | (acc[0] & 0x0003);
|
||||
if(acc[0] & 0x0200) acc[0] |= 0xFC00;
|
||||
|
||||
// Y LSB
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
|
||||
acc[1] = (I2C_ReceiveData(I2C1) & 0xC0) >> 6;
|
||||
// Y MSB
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
|
||||
acc[1] = (I2C_ReceiveData(I2C1) & 0xFF) << 2 | (acc[1] & 0x0003);
|
||||
if(acc[1] & 0x0200) acc[1] |= 0xFC00;
|
||||
|
||||
// Z LSB
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
|
||||
acc[2] = (I2C_ReceiveData(I2C1) & 0xC0) >> 6;
|
||||
// Z MSB
|
||||
I2C_AcknowledgeConfig(I2C1, DISABLE);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
|
||||
acc[2] = (I2C_ReceiveData(I2C1) & 0xFF) << 2 | (acc[2] & 0x0003);
|
||||
if(acc[2] & 0x0200) acc[2] |= 0xFC00;
|
||||
|
||||
I2C_GenerateSTOP(I2C1, ENABLE);
|
||||
|
||||
acc_f[0] = 2.0f * ((float)acc[0]/512);
|
||||
acc_f[1] = 2.0f * ((float)acc[1]/512);
|
||||
acc_f[2] = 2.0f * ((float)acc[2]/512);
|
||||
}
|
||||
|
||||
void deinit_bma(void)
|
||||
{
|
||||
I2C_Cmd(I2C1, DISABLE);
|
||||
I2C_DeInit(I2C1);
|
||||
}
|
18
Mieke/SW/MT/bma.h
Normal file
18
Mieke/SW/MT/bma.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef BMA_H
|
||||
#define BMA_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
#include "stm32f10x_i2c.h" // Keil::Device:StdPeriph Drivers:I2C
|
||||
|
||||
#define BMA_ADDR (uint8_t)0x70 // 0b01110000
|
||||
// ---- Vendor address part
|
||||
// --- User address part
|
||||
// - Keep free for R/W bit (set by I2C_Send7bitAddress())
|
||||
|
||||
void init_bma(void);
|
||||
void run_bma(float acc_f[3]);
|
||||
void deinit_bma(void);
|
||||
|
||||
#endif
|
67
Mieke/SW/MT/display.c
Normal file
67
Mieke/SW/MT/display.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "display.h"
|
||||
|
||||
#define COLORS 8
|
||||
|
||||
uint8_t i = 0;
|
||||
char colors[COLORS][7] = {
|
||||
"RED",
|
||||
"BLUE",
|
||||
"GRAY",
|
||||
"BLACK",
|
||||
"WHITE",
|
||||
"GREEN",
|
||||
"BROWN",
|
||||
"YELLOW"
|
||||
};
|
||||
|
||||
void init_display(void)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
gpio.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
USART_InitTypeDef usart;
|
||||
USART_StructInit(&usart);
|
||||
usart.USART_BaudRate = 9600;
|
||||
USART_Init(USART3, &usart);
|
||||
|
||||
USART_ClockInitTypeDef usartclock;
|
||||
USART_ClockStructInit(&usartclock);
|
||||
USART_ClockInit(USART3, &usartclock);
|
||||
|
||||
USART_Cmd(USART3, ENABLE);
|
||||
}
|
||||
|
||||
void run_display(void)
|
||||
{
|
||||
char cmd[16], *cptr;
|
||||
cptr = cmd;
|
||||
sprintf(cmd, "cls %s\xFF\xFF\xFF", colors[i++]);
|
||||
if (i == COLORS) i = 0;
|
||||
while(*cptr) {
|
||||
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
|
||||
USART_SendData(USART3, *cptr++);
|
||||
}
|
||||
}
|
||||
|
||||
void deinit_display(void)
|
||||
{
|
||||
char *cmd = "rest\xFF\xFF\xFF";
|
||||
while(*cmd) {
|
||||
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
|
||||
USART_SendData(USART3, *cmd++);
|
||||
}
|
||||
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
|
||||
USART_Cmd(USART3, DISABLE);
|
||||
USART_DeInit(USART3);
|
||||
}
|
15
Mieke/SW/MT/display.h
Normal file
15
Mieke/SW/MT/display.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
#include "stm32f10x_usart.h" // Keil::Device:StdPeriph Drivers:USART
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void init_display(void);
|
||||
void run_display(void);
|
||||
void deinit_display(void);
|
||||
|
||||
#endif
|
123
Mieke/SW/MT/eeprom.c
Normal file
123
Mieke/SW/MT/eeprom.c
Normal file
|
@ -0,0 +1,123 @@
|
|||
#include "eeprom.h"
|
||||
|
||||
volatile uint32_t *EEPROMSTick, EEPROMSTickCur;
|
||||
|
||||
uint8_t load_byte(uint16_t eeprom_addr)
|
||||
{
|
||||
uint8_t data;
|
||||
I2C_GenerateSTART(I2C1, ENABLE);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
|
||||
I2C_Send7bitAddress(I2C1, EEPROM_ADDR, I2C_Direction_Transmitter);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
|
||||
I2C_SendData(I2C1, (eeprom_addr & 0xFF00) >> 8);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
|
||||
I2C_SendData(I2C1, (eeprom_addr & 0x00FF));
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
|
||||
|
||||
I2C_GenerateSTART(I2C1, ENABLE);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
|
||||
I2C_Send7bitAddress(I2C1, EEPROM_ADDR, I2C_Direction_Receiver);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
|
||||
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
|
||||
data = I2C_ReceiveData(I2C1);
|
||||
I2C_GenerateSTOP(I2C1, ENABLE);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void write_byte(uint16_t eeprom_addr, uint8_t data)
|
||||
{
|
||||
I2C_GenerateSTART(I2C1, ENABLE);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
|
||||
I2C_Send7bitAddress(I2C1, EEPROM_ADDR, I2C_Direction_Transmitter);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
|
||||
I2C_SendData(I2C1, (eeprom_addr & 0xFF00) >> 8);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
|
||||
I2C_SendData(I2C1, (eeprom_addr & 0x00FF));
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
|
||||
|
||||
I2C_SendData(I2C1, data);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
|
||||
|
||||
I2C_GenerateSTOP(I2C1, ENABLE);
|
||||
|
||||
EEPROMSTickCur = *EEPROMSTick;
|
||||
while((*EEPROMSTick - EEPROMSTickCur) <= 50); // 5ms write cycle, see datasheet param 17
|
||||
return;
|
||||
}
|
||||
|
||||
void init_eeprom(volatile uint32_t *SysTickCnt)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
// SCL
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_6;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
// SDA
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
gpio.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
I2C_InitTypeDef i2c;
|
||||
I2C_StructInit(&i2c);
|
||||
i2c.I2C_ClockSpeed = 400000;
|
||||
I2C_Init(I2C1, &i2c);
|
||||
|
||||
I2C_Cmd(I2C1, ENABLE);
|
||||
EEPROMSTick = SysTickCnt;
|
||||
return;
|
||||
}
|
||||
|
||||
void run_eeprom(uint8_t *success)
|
||||
{
|
||||
uint8_t set, read;
|
||||
*success = 0;
|
||||
set = 0xAA;
|
||||
write_byte(0x0000, set);
|
||||
read = load_byte(0x0000);
|
||||
if (set != read) return;
|
||||
set = 0xBA;
|
||||
write_byte(0x0010, set);
|
||||
read = load_byte(0x0010);
|
||||
if (set != read) return;
|
||||
set = 0xAD;
|
||||
write_byte(0x0001, set);
|
||||
read = load_byte(0x0001);
|
||||
if (set != read) return;
|
||||
set = 0x00;
|
||||
write_byte(0x0000, set);
|
||||
read = load_byte(0x0000);
|
||||
if (set != read) return;
|
||||
set = 0x88;
|
||||
write_byte(0x0002, set);
|
||||
read = load_byte(0x0002);
|
||||
if (set != read) return;
|
||||
set = 0x01;
|
||||
write_byte(0x0000, set);
|
||||
read = load_byte(0x0000);
|
||||
if (set != read) return;
|
||||
set = 0x55;
|
||||
write_byte(0x00005, set);
|
||||
read = load_byte(0x0005);
|
||||
if (set != read) return;
|
||||
set = 0xAA;
|
||||
write_byte(0x0005, set);
|
||||
read = load_byte(0x0005);
|
||||
if (set != read) return;
|
||||
*success = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
void deinit_eeprom(void)
|
||||
{
|
||||
I2C_Cmd(I2C1, DISABLE);
|
||||
I2C_DeInit(I2C1);
|
||||
return;
|
||||
}
|
18
Mieke/SW/MT/eeprom.h
Normal file
18
Mieke/SW/MT/eeprom.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef EEPROM_H
|
||||
#define EEPROM_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
#include "stm32f10x_i2c.h" // Keil::Device:StdPeriph Drivers:I2C
|
||||
|
||||
#define EEPROM_ADDR (uint8_t)0xA0 // 0b10100000
|
||||
// ---- Vendor address part
|
||||
// --- User address part
|
||||
// - Keep free for R/W bit (set by I2C_Send7bitAddress())
|
||||
|
||||
void init_eeprom(volatile uint32_t *SysTickCnt);
|
||||
void run_eeprom(uint8_t *success);
|
||||
void deinit_eeprom(void);
|
||||
|
||||
#endif
|
76
Mieke/SW/MT/esp.c
Normal file
76
Mieke/SW/MT/esp.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include "esp.h"
|
||||
|
||||
void init_esp(void)
|
||||
{
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_Init(GPIOA, &gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
gpio.GPIO_Pin = GPIO_Pin_3;
|
||||
GPIO_Init(GPIOA, &gpio);
|
||||
|
||||
USART_InitTypeDef usart;
|
||||
USART_StructInit(&usart);
|
||||
usart.USART_BaudRate = 115200;
|
||||
USART_Init(USART2, &usart);
|
||||
|
||||
USART_ClockInitTypeDef usartclock;
|
||||
USART_ClockStructInit(&usartclock);
|
||||
USART_ClockInit(USART2, &usartclock);
|
||||
|
||||
NVIC_InitTypeDef nvic;
|
||||
nvic.NVIC_IRQChannel = USART2_IRQn;
|
||||
nvic.NVIC_IRQChannelCmd = ENABLE;
|
||||
nvic.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
nvic.NVIC_IRQChannelSubPriority = 2;
|
||||
NVIC_Init(&nvic);
|
||||
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_Cmd(USART2, ENABLE);
|
||||
}
|
||||
|
||||
void esp_wait()
|
||||
{
|
||||
int i, j;
|
||||
for(j=0;j<500;j++) {
|
||||
for(i=0;i<65536;i++);
|
||||
}
|
||||
}
|
||||
|
||||
void send_str(char *str) {
|
||||
while(*str) {
|
||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
|
||||
USART_SendData(USART2, *str++);
|
||||
}
|
||||
}
|
||||
|
||||
void run_esp(void)
|
||||
{
|
||||
send_str("AT+RESTORE\r\n");
|
||||
esp_wait();
|
||||
send_str("AT+CWMODE?\r\n");
|
||||
esp_wait();
|
||||
send_str("AT+CWMODE=2\r\n");
|
||||
esp_wait();
|
||||
send_str("AT+RST\r\n");
|
||||
esp_wait();
|
||||
send_str("AT+CIPMUX=1\r\n");
|
||||
esp_wait();
|
||||
send_str("AT+CIPSERVER=1,2526\r\n");
|
||||
esp_wait();
|
||||
send_str("AT+CIPAP_CUR?\r\n");
|
||||
}
|
||||
|
||||
void deinit_esp(void)
|
||||
{
|
||||
USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
|
||||
USART_Cmd(USART2, DISABLE);
|
||||
USART_DeInit(USART2);
|
||||
}
|
13
Mieke/SW/MT/esp.h
Normal file
13
Mieke/SW/MT/esp.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef ESP_H
|
||||
#define ESP_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
#include "stm32f10x_usart.h" // Keil::Device:StdPeriph Drivers:USART
|
||||
|
||||
void init_esp(void);
|
||||
void run_esp(void);
|
||||
void deinit_esp(void);
|
||||
|
||||
#endif
|
139
Mieke/SW/MT/interface_uart.c
Normal file
139
Mieke/SW/MT/interface_uart.c
Normal file
|
@ -0,0 +1,139 @@
|
|||
#include "interface_uart.h"
|
||||
|
||||
void USART_SendString(USART_TypeDef *USARTx, char *str)
|
||||
{
|
||||
while (*str) {
|
||||
while (USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET);
|
||||
USART_SendData(USARTx, *str++);
|
||||
}
|
||||
}
|
||||
|
||||
void init_all(void)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_9;
|
||||
GPIO_Init(GPIOA, &gpio);
|
||||
|
||||
gpio.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_Init(GPIOA, &gpio);
|
||||
|
||||
gpio.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
gpio.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_Init(GPIOA, &gpio);
|
||||
|
||||
gpio.GPIO_Pin = GPIO_Pin_3;
|
||||
GPIO_Init(GPIOA, &gpio);
|
||||
|
||||
gpio.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
USART_InitTypeDef usart;
|
||||
USART_StructInit(&usart);
|
||||
usart.USART_BaudRate = 115200;
|
||||
USART_Init(USART1, &usart);
|
||||
USART_Init(USART2, &usart);
|
||||
USART_Init(USART3, &usart);
|
||||
|
||||
USART_ClockInitTypeDef usartclock;
|
||||
USART_ClockStructInit(&usartclock);
|
||||
USART_ClockInit(USART1, &usartclock);
|
||||
USART_ClockInit(USART2, &usartclock);
|
||||
USART_ClockInit(USART3, &usartclock);
|
||||
|
||||
USART_Cmd(USART1, ENABLE);
|
||||
USART_Cmd(USART2, ENABLE);
|
||||
USART_Cmd(USART3, ENABLE);
|
||||
|
||||
RCC_ClocksTypeDef clocks;
|
||||
RCC_GetClocksFreq(&clocks);
|
||||
SysTick_Config(clocks.HCLK_Frequency/1000 - 1); // SysTick T=1ms
|
||||
}
|
||||
|
||||
void send_welcome(void)
|
||||
{
|
||||
USART_SendString(USART1, "\x1B[2J\x1B[0;0HManufacturing test software, press space...\r\n");
|
||||
USART_SendString(USART2, "\x1B[2J\x1B[0;0HManufacturing test software, press space...\r\n");
|
||||
USART_SendString(USART3, "\x1B[2J\x1B[0;0HManufacturing test software, press space...\r\n");
|
||||
}
|
||||
|
||||
unsigned int wait_for_start(void)
|
||||
{
|
||||
uint8_t data;
|
||||
for(;;) {
|
||||
if (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET) {
|
||||
data = USART_ReceiveData(USART1);
|
||||
if (data == ' ') {
|
||||
USART_Cmd(USART2, DISABLE);
|
||||
USART_Cmd(USART3, DISABLE);
|
||||
USART_DeInit(USART2);
|
||||
USART_DeInit(USART3);
|
||||
return 1;
|
||||
} else {
|
||||
USART_Cmd(USART1, DISABLE);
|
||||
USART_DeInit(USART1);
|
||||
}
|
||||
}
|
||||
if (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == SET) {
|
||||
data = USART_ReceiveData(USART2);
|
||||
if (data == ' ') {
|
||||
USART_Cmd(USART1, DISABLE);
|
||||
USART_Cmd(USART3, DISABLE);
|
||||
USART_DeInit(USART1);
|
||||
USART_DeInit(USART3);
|
||||
return 2;
|
||||
} else {
|
||||
USART_Cmd(USART2, DISABLE);
|
||||
USART_DeInit(USART2);
|
||||
}
|
||||
}
|
||||
if (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET) {
|
||||
data = USART_ReceiveData(USART3);
|
||||
if (data == ' ') {
|
||||
USART_Cmd(USART1, DISABLE);
|
||||
USART_Cmd(USART2, DISABLE);
|
||||
USART_DeInit(USART1);
|
||||
USART_DeInit(USART2);
|
||||
return 3;
|
||||
} else {
|
||||
USART_Cmd(USART3, DISABLE);
|
||||
USART_DeInit(USART3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int wait_for_test(USART_TypeDef *USARTx)
|
||||
{
|
||||
int data;
|
||||
for(;;)
|
||||
{
|
||||
if (USART_GetFlagStatus(USARTx, USART_FLAG_RXNE) == SET) {
|
||||
data = (int)USART_ReceiveData(USARTx);
|
||||
if ((data > 0x09 && data <= 0x30) || data > 0x39) return 1;
|
||||
return (data >= 0x30) ? data - 0x30 : data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int get_test(USART_TypeDef *USARTx)
|
||||
{
|
||||
int data;
|
||||
if (USART_GetFlagStatus(USARTx, USART_FLAG_RXNE) == SET) {
|
||||
data = (int)USART_ReceiveData(USARTx);
|
||||
if ((data > 0x09 && data <= 0x30) || data > 0x39) return 1;
|
||||
return (data >= 0x30) ? data - 0x30 : data;
|
||||
}
|
||||
return 0;
|
||||
}
|
16
Mieke/SW/MT/interface_uart.h
Normal file
16
Mieke/SW/MT/interface_uart.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef INTERFACE_UART_H
|
||||
#define INTERFACE_UART_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
#include "stm32f10x_usart.h" // Keil::Device:StdPeriph Drivers:USART
|
||||
|
||||
void USART_SendString(USART_TypeDef *USARTx, char *str);
|
||||
void init_all(void);
|
||||
void send_welcome(void);
|
||||
unsigned int wait_for_start(void);
|
||||
unsigned int wait_for_test(USART_TypeDef *USARTx);
|
||||
unsigned int get_test(USART_TypeDef *USARTx);
|
||||
|
||||
#endif
|
31
Mieke/SW/MT/ledswitch.c
Normal file
31
Mieke/SW/MT/ledswitch.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "ledswitch.h"
|
||||
|
||||
void init_ledswitch(void)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
|
||||
GPIO_Init(GPIOC, &gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_IPU;
|
||||
gpio.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8;
|
||||
GPIO_Init(GPIOA, &gpio);
|
||||
return;
|
||||
}
|
||||
|
||||
void run_ledswitch(uint8_t *switches)
|
||||
{
|
||||
*switches = (GPIO_ReadInputData(GPIOA) & 0x000F) | ((GPIO_ReadInputData(GPIOA) & 0x01E0) >> 1);
|
||||
GPIO_Write(GPIOC, ((*switches & 0xE0) << 2) | ((*switches & 0x1F) << 1));
|
||||
return;
|
||||
}
|
||||
|
||||
void deinit_ledswitch(void)
|
||||
{
|
||||
return;
|
||||
}
|
12
Mieke/SW/MT/ledswitch.h
Normal file
12
Mieke/SW/MT/ledswitch.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef LEDSWITCH_H
|
||||
#define LEDSWITCH_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
|
||||
void init_ledswitch(void);
|
||||
void run_ledswitch(uint8_t *switches);
|
||||
void deinit_ledswitch(void);
|
||||
|
||||
#endif
|
234
Mieke/SW/MT/main.c
Normal file
234
Mieke/SW/MT/main.c
Normal file
|
@ -0,0 +1,234 @@
|
|||
#include <stdio.h>
|
||||
#include "interface_uart.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include "bma.h"
|
||||
#include "ne555.h"
|
||||
#include "ledswitch.h"
|
||||
#include "eeprom.h"
|
||||
#include "esp.h"
|
||||
#include "rgb.h"
|
||||
#include "piezo.h"
|
||||
#include "display.h"
|
||||
|
||||
volatile uint32_t SysTickCnt = 0;
|
||||
USART_TypeDef *used_usart;
|
||||
|
||||
void SysTick_Handler()
|
||||
{
|
||||
SysTickCnt++;
|
||||
}
|
||||
|
||||
void USART2_IRQHandler()
|
||||
{
|
||||
USART_SendData(used_usart, USART_ReceiveData(USART2));
|
||||
}
|
||||
|
||||
void wait(uint32_t ms)
|
||||
{
|
||||
uint32_t SysTickCntHold = SysTickCnt;
|
||||
while((SysTickCnt - SysTickCntHold) <= ms);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
char buffer[1024];
|
||||
enum test_t current_test = test_not_init, next_test = test_not_init;
|
||||
enum iface_t control_interface = interface_none;
|
||||
|
||||
for (;;) {
|
||||
switch (control_interface) {
|
||||
case interface_none:
|
||||
init_all();
|
||||
send_welcome();
|
||||
control_interface = (enum iface_t)wait_for_start();
|
||||
switch (control_interface) {
|
||||
case interface_usart1:
|
||||
used_usart = USART1;
|
||||
break;
|
||||
case interface_usart2:
|
||||
used_usart = USART2;
|
||||
break;
|
||||
case interface_usart3:
|
||||
used_usart = USART3;
|
||||
break;
|
||||
default:
|
||||
control_interface = interface_none;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case interface_usart1:
|
||||
case interface_usart2:
|
||||
case interface_usart3:
|
||||
switch(current_test) {
|
||||
case test_not_init:
|
||||
current_test = test_none;
|
||||
break;
|
||||
case test_none:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HManufacturing test software, Version " VERSION "\r\n\r\n\
|
||||
\tTo run tests, enter one of the following numbers:\r\n\t\t[2]\tBMA\r\n\t\t[3]\tNE555/LFU/IR\r\n\
|
||||
\t\t[4]\tLEDs and Switches\r\n\t\t[5]\tESP\r\n\t\t[6]\tEEPROM\r\n\t\t[7]\tRGB LED\r\n\t\t[8]\tPiezo\r\n\t\t[9]\tDisplay\r\n\r\nWaiting for your selection... ");
|
||||
current_test = (enum test_t)wait_for_test(used_usart);
|
||||
break;
|
||||
case test_bma:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HBMA Test\r\n\r\nThis tests the correct function\
|
||||
of the used BMA gyroscope as well as I2C port 1. Below you should see the current acceleration values printed\
|
||||
for the X, Y and Z axis. Where the Z axis should show something around 1g, as this is the gravitational\
|
||||
acceleration on the Earth, of course this value is lower if you run this program on the moon!\r\n\r\n\
|
||||
To return to the main menu press a button.\r\n\r\n\r\n");
|
||||
init_bma();
|
||||
float accs[3];
|
||||
for(;;) {
|
||||
run_bma(accs);
|
||||
sprintf(buffer, "\x1B[K\rX: % 02.5f, Y: % 02.5f, Z: % 02.5f", accs[0], accs[1], accs[2]);
|
||||
USART_SendString(used_usart, buffer);
|
||||
next_test = (enum test_t)get_test(used_usart);
|
||||
if (next_test != test_not_init) {
|
||||
current_test = next_test;
|
||||
deinit_bma();
|
||||
break;
|
||||
}
|
||||
wait(50);
|
||||
}
|
||||
break;
|
||||
case test_ne555:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HNE555/LFU/IR Test\r\n\r\nThis tests the correct function\
|
||||
of the NE555/LFU/IR on the board. The currently selected frequency should be printed below!\r\n\r\n\
|
||||
To return to the main menu press a button.\r\n\r\n\r\n");
|
||||
init_ne555(&SysTickCnt);
|
||||
float freq;
|
||||
for(;;) {
|
||||
run_ne555(&freq);
|
||||
sprintf(buffer, "\x1B[K\r% 05.1fHz", freq);
|
||||
USART_SendString(used_usart, buffer);
|
||||
next_test = (enum test_t)get_test(used_usart);
|
||||
if (next_test != test_not_init) {
|
||||
current_test = next_test;
|
||||
deinit_ne555();
|
||||
break;
|
||||
}
|
||||
wait(50);
|
||||
}
|
||||
break;
|
||||
case test_led:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HLED/Switch Test\r\n\r\nThis tests the correct function\
|
||||
of the switches and the leds on the board. The currently selected leds are shown hexadecimal below!\r\n\r\n\
|
||||
To return to the main menu press a button.\r\n\r\n\r\n");
|
||||
init_ledswitch();
|
||||
uint8_t switches;
|
||||
for(;;) {
|
||||
run_ledswitch(&switches);
|
||||
sprintf(buffer, "\x1B[K\rSelected: 0x%02x", switches);
|
||||
USART_SendString(used_usart, buffer);
|
||||
next_test = (enum test_t)get_test(used_usart);
|
||||
if (next_test != test_not_init) {
|
||||
current_test = next_test;
|
||||
deinit_ledswitch();
|
||||
break;
|
||||
}
|
||||
wait(50);
|
||||
}
|
||||
break;
|
||||
case test_esp:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HESP Test\r\n\r\nThis tests the correct function\
|
||||
of the ESP module on the board. The ESP should open a WLAN AP!\r\n\r\n\
|
||||
To return to the main menu press a button.\r\n\r\n\r\n");
|
||||
init_esp();
|
||||
sprintf(buffer, "\x1B[K\rRunning test...\r\n\r\n");
|
||||
USART_SendString(used_usart, buffer);
|
||||
run_esp();
|
||||
for(;;) {
|
||||
next_test = (enum test_t)get_test(used_usart);
|
||||
if (next_test != test_not_init) {
|
||||
current_test = next_test;
|
||||
deinit_esp();
|
||||
break;
|
||||
}
|
||||
wait(50);
|
||||
}
|
||||
break;
|
||||
case test_eeprom:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HEEPROM Test\r\n\r\nThis tests the correct function\
|
||||
of the EEPROM on the board. The test will run and show an OK or NOK below!\r\n\r\n\
|
||||
To return to the main menu press a button.\r\n\r\n\r\n");
|
||||
init_eeprom(&SysTickCnt);
|
||||
uint8_t success;
|
||||
sprintf(buffer, "\x1B[K\rRunning test...");
|
||||
USART_SendString(used_usart, buffer);
|
||||
run_eeprom(&success);
|
||||
if(success == 1) sprintf(buffer, "OK");
|
||||
else sprintf(buffer, "NOK");
|
||||
USART_SendString(used_usart, buffer);
|
||||
for(;;) {
|
||||
next_test = (enum test_t)get_test(used_usart);
|
||||
if (next_test != test_not_init) {
|
||||
current_test = next_test;
|
||||
deinit_eeprom();
|
||||
break;
|
||||
}
|
||||
wait(50);
|
||||
}
|
||||
break;
|
||||
case test_rgb:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HRGB LED Test\r\n\r\nThis tests the correct function\
|
||||
of the RGB LED and it's I2C driver on the board!\r\n\r\n\
|
||||
To return to the main menu press a button.\r\n\r\n\r\n");
|
||||
init_rgb();
|
||||
for(;;) {
|
||||
run_rgb();
|
||||
next_test = (enum test_t)get_test(used_usart);
|
||||
if (next_test != test_not_init) {
|
||||
current_test = next_test;
|
||||
deinit_rgb();
|
||||
break;
|
||||
}
|
||||
wait(50);
|
||||
}
|
||||
break;
|
||||
case test_piezo:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HPiezo Test\r\n\r\nThis tests the correct function\
|
||||
of the Piezo on the board. You should hear the frequency printed below!\r\n\r\n\
|
||||
To return to the main menu press a button.\r\n\r\n\r\n");
|
||||
init_piezo(&SysTickCnt);
|
||||
for(;;) {
|
||||
run_piezo();
|
||||
sprintf(buffer, "\x1B[K\r500Hz");
|
||||
USART_SendString(used_usart, buffer);
|
||||
next_test = (enum test_t)get_test(used_usart);
|
||||
if (next_test != test_not_init) {
|
||||
current_test = next_test;
|
||||
deinit_piezo();
|
||||
break;
|
||||
}
|
||||
wait(50);
|
||||
}
|
||||
break;
|
||||
case test_display:
|
||||
USART_SendString(used_usart, "\x1B[2J\x1B[0;0HDisplay Test\r\n\r\nThis tests the correct function\
|
||||
of the Display on the board. You should see text printed on the display!\r\n\r\n\
|
||||
To return to the main menu press a button.\r\n\r\n\r\n");
|
||||
init_display();
|
||||
for(;;) {
|
||||
run_display();
|
||||
sprintf(buffer, "OK");
|
||||
USART_SendString(used_usart, buffer);
|
||||
next_test = (enum test_t)get_test(used_usart);
|
||||
if (next_test != test_not_init) {
|
||||
current_test = next_test;
|
||||
deinit_display();
|
||||
break;
|
||||
}
|
||||
wait(50);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
current_test = test_none;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
30
Mieke/SW/MT/main.h
Normal file
30
Mieke/SW/MT/main.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#define VERSION "0.1.0"
|
||||
|
||||
enum iface_t {
|
||||
interface_none = 0,
|
||||
interface_usart1,
|
||||
interface_usart2,
|
||||
interface_usart3
|
||||
};
|
||||
|
||||
enum test_t {
|
||||
test_not_init = 0,
|
||||
test_none = 1,
|
||||
test_bma,
|
||||
test_ne555,
|
||||
test_led,
|
||||
test_esp,
|
||||
test_eeprom,
|
||||
test_rgb,
|
||||
test_piezo,
|
||||
test_display
|
||||
};
|
||||
|
||||
void SysTick_Handler(void);
|
||||
void USART2_IRQHandler(void);
|
||||
void wait(uint32_t ms);
|
||||
|
||||
#endif
|
42
Mieke/SW/MT/ne555.c
Normal file
42
Mieke/SW/MT/ne555.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "ne555.h"
|
||||
|
||||
volatile uint32_t *NE555STick, NE555STickCur;
|
||||
uint8_t old_state;
|
||||
|
||||
void init_ne555(volatile uint32_t *SysTickCnt)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
gpio.GPIO_Pin = GPIO_Pin_0;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
NE555STick = SysTickCnt;
|
||||
return;
|
||||
}
|
||||
|
||||
void run_ne555(float *freq)
|
||||
{
|
||||
uint8_t state;
|
||||
*freq = 0.0f;
|
||||
NE555STickCur = *NE555STick;
|
||||
while((*NE555STick - NE555STickCur) <= 1000)
|
||||
{
|
||||
state = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0);
|
||||
if (state != old_state)
|
||||
{
|
||||
(*freq)++;
|
||||
old_state = state;
|
||||
}
|
||||
}
|
||||
*freq /= 2;
|
||||
return;
|
||||
}
|
||||
|
||||
void deinit_ne555(void)
|
||||
{
|
||||
return;
|
||||
}
|
12
Mieke/SW/MT/ne555.h
Normal file
12
Mieke/SW/MT/ne555.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef NE555_H
|
||||
#define NE555_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
|
||||
void init_ne555(volatile uint32_t *SysTickCnt);
|
||||
void run_ne555(float *freq);
|
||||
void deinit_ne555(void);
|
||||
|
||||
#endif
|
42
Mieke/SW/MT/piezo.c
Normal file
42
Mieke/SW/MT/piezo.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "piezo.h"
|
||||
|
||||
volatile uint32_t *PiezoSTick, PiezoSTickCur, Freq;
|
||||
|
||||
void init_piezo(volatile uint32_t *SysTickCnt)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_0;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
PiezoSTick = SysTickCnt;
|
||||
return;
|
||||
}
|
||||
|
||||
void run_piezo()
|
||||
{
|
||||
uint8_t pstate = 0x0;
|
||||
PiezoSTickCur = *PiezoSTick;
|
||||
while((*PiezoSTick - PiezoSTickCur) <= 1000)
|
||||
{
|
||||
Freq = *PiezoSTick;
|
||||
while((*PiezoSTick - Freq) <= 1);
|
||||
if (pstate) {
|
||||
pstate = ~pstate;
|
||||
GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_SET);
|
||||
} else {
|
||||
pstate = ~pstate;
|
||||
GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_RESET);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void deinit_piezo(void)
|
||||
{
|
||||
return;
|
||||
}
|
12
Mieke/SW/MT/piezo.h
Normal file
12
Mieke/SW/MT/piezo.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef PIEZO_H
|
||||
#define PIEZO_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
|
||||
void init_piezo(volatile uint32_t *SysTickCnt);
|
||||
void run_piezo(void);
|
||||
void deinit_piezo(void);
|
||||
|
||||
#endif
|
89
Mieke/SW/MT/rgb.c
Normal file
89
Mieke/SW/MT/rgb.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include "rgb.h"
|
||||
#include "main.h"
|
||||
|
||||
typedef enum {
|
||||
RGB_SHUTDOWN = 0x00,
|
||||
RGB_MAXCUR,
|
||||
RGB_RED,
|
||||
RGB_GREEN,
|
||||
RGB_BLUE,
|
||||
RGB_UPLEND,
|
||||
RGB_DOWNLEND,
|
||||
RGB_DIMSTEP
|
||||
} RGB_T;
|
||||
|
||||
|
||||
void rgb_send_command(uint8_t data)
|
||||
{
|
||||
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));
|
||||
|
||||
I2C_SendData(I2C1, data);
|
||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
|
||||
|
||||
I2C_GenerateSTOP(I2C1, ENABLE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void init_rgb(void)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio;
|
||||
GPIO_StructInit(&gpio);
|
||||
|
||||
// SCL
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
gpio.GPIO_Pin = GPIO_Pin_6;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
// SDA
|
||||
gpio.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
gpio.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
I2C_InitTypeDef i2c;
|
||||
I2C_StructInit(&i2c);
|
||||
i2c.I2C_ClockSpeed = 400000;
|
||||
I2C_Init(I2C1, &i2c);
|
||||
|
||||
I2C_Cmd(I2C1, ENABLE);
|
||||
|
||||
// LED actually allows 40mA, but driver only hanbdles around 30
|
||||
rgb_send_command(0x3F);
|
||||
return;
|
||||
}
|
||||
|
||||
void run_rgb(void)
|
||||
{
|
||||
rgb_send_command(0x5F);
|
||||
wait(100);
|
||||
rgb_send_command(0x7F);
|
||||
wait(100);
|
||||
rgb_send_command(0x9F);
|
||||
wait(100);
|
||||
rgb_send_command(0x50);
|
||||
wait(100);
|
||||
rgb_send_command(0x70);
|
||||
wait(100);
|
||||
rgb_send_command(0x90);
|
||||
wait(100);
|
||||
rgb_send_command(0x40);
|
||||
wait(100);
|
||||
rgb_send_command(0x60);
|
||||
wait(100);
|
||||
rgb_send_command(0x80);
|
||||
wait(100);
|
||||
return;
|
||||
}
|
||||
|
||||
void deinit_rgb(void)
|
||||
{
|
||||
I2C_Cmd(I2C1, DISABLE);
|
||||
I2C_DeInit(I2C1);
|
||||
return;
|
||||
}
|
18
Mieke/SW/MT/rgb.h
Normal file
18
Mieke/SW/MT/rgb.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef RGB_H
|
||||
#define RGB_H
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC
|
||||
#include "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
|
||||
#include "stm32f10x_i2c.h" // Keil::Device:StdPeriph Drivers:I2C
|
||||
|
||||
#define RGB_ADDR (uint8_t)0x70 // 0b01110000
|
||||
// ---- Vendor address part
|
||||
// --- User address part
|
||||
// - Keep free for R/W bit (set by I2C_Send7bitAddress())
|
||||
|
||||
void init_rgb(void);
|
||||
void run_rgb(void);
|
||||
void deinit_rgb(void);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue