Skip to content

Commit 7235aeb

Browse files
author
mars
committed
doubled PWM frequency, cleaned up code
1 parent 9060a52 commit 7235aeb

1 file changed

Lines changed: 3 additions & 50 deletions

File tree

firmware/Source/periph.c

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const uint16_t pwmvalues[LED_FULL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
88

99
void initializeTimer(){
1010
uint16_t prescaler = (int16_t)(SystemCoreClock / 2000000) - 1; // 2Mhz clock
11-
uint16_t period = 1000000 / 20000; // 40 KHz for 2MHz prescaled
11+
uint16_t period = 2000000 / 20000; // 20 KHz for 2MHz prescaled
1212
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
1313
TIM_TimeBaseInitTypeDef init = {
1414
.TIM_Prescaler = prescaler,
@@ -21,7 +21,6 @@ void initializeTimer(){
2121
TIM_Cmd(TIM3, ENABLE);
2222
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
2323
}
24-
// TIM3_CH1 PA6 no remap
2524

2625
void setPWM(uint16_t pulse){
2726
static TIM_OCInitTypeDef init = {
@@ -34,19 +33,17 @@ void setPWM(uint16_t pulse){
3433
}
3534

3635
void initializeLED(){
37-
// RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
3836
GPIO_InitTypeDef gpioStructure;
3937
gpioStructure.GPIO_Pin = GPIO_Pin_6;
4038
gpioStructure.GPIO_Mode = GPIO_Mode_AF_PP;
4139
gpioStructure.GPIO_Speed = GPIO_Speed_2MHz;
4240
GPIO_Init(GPIOA, &gpioStructure);
43-
// GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_TIM3);
4441
}
4542

4643
void setLed(uint16_t brightness){
4744
static uint16_t value = 0;
4845
if(brightness != value){
49-
setPWM(pwmvalues[brightness]);
46+
setPWM(pwmvalues[brightness]); // pw: 0 to 100
5047
value = brightness;
5148
}
5249
}
@@ -55,56 +52,12 @@ char* getFirmwareVersion(){
5552
return HARDWARE_VERSION "-" FIRMWARE_VERSION ;
5653
}
5754

58-
/* Unique device ID register (96 bits: 12 bytes) */
59-
uint8_t* getDeviceId(){
60-
const uint32_t* addr = (uint32_t*)0x1fff7a10;
61-
static uint32_t deviceId[3];
62-
deviceId[0] = addr[0];
63-
deviceId[1] = addr[1];
64-
deviceId[2] = addr[2];
65-
return (uint8_t*)deviceId;
66-
67-
// read location 0xE0042000
68-
// 16 bits revision id, 4 bits reserved, 12 bits device id
69-
/* 0x1000 = Revision A, 0x1001 = Revision Z */
70-
71-
/* The ARM CortexTM-M4F integrates a JEDEC-106 ID code. It is located in the 4KB ROM table mapped on the internal PPB bus at address 0xE00FF000_0xE00FFFFF. */
72-
73-
/* return DBGMCU_GetREVID() << 16 | DBGMCU_GetDEVID(); */
74-
}
75-
76-
__attribute__((naked))
77-
void dfu_reboot(void){
78-
/* asm volatile("ldr r0, =0x1fff0000\n" */
79-
/* "ldr sp, [r0, #0]\n" */
80-
/* "ldr r0, [r0, #4]\n" */
81-
/* "bx r0\n"); */
82-
83-
/* This address is within the first 64k of memory.
84-
* The magic number must match what is in the bootloader */
85-
*((unsigned long *)0x2000FFF0) = 0xaeaaefaf ^ 0x00f00b44ff;
86-
87-
NVIC_SystemReset();
88-
89-
/* Shouldn't get here */
90-
while(1);
91-
}
92-
93-
/* LedPin getLed(){ */
94-
/* if(getPin(LED_PORT, LED_GREEN)) */
95-
/* return GREEN; */
96-
/* else if(getPin(LED_PORT, LED_RED)) */
97-
/* return RED; */
98-
/* else */
99-
/* return NONE; */
100-
/* } */
101-
10255
void ledSetup(){
10356
configureDigitalOutput(LED_PORT, LED_RED|LED_GREEN);
10457
clearPin(LED_PORT, LED_RED|LED_GREEN);
10558
initializeLED();
10659
initializeTimer();
107-
setPWM(0); // pw: 1 to 50
60+
setPWM(0);
10861
}
10962

11063
bool isPushButtonPressed(){

0 commit comments

Comments
 (0)