Compare commits

...

3 Commits

Author SHA1 Message Date
  Emil Renner Berthing 9651c10bcb Cycle through "animations" on button click 5 years ago
  Emil Renner Berthing 11e6ebeb0d inc/hw_pinout.h: fix whitespace 5 years ago
  Emil Renner Berthing 0acbfcf61f Makefile: add -O2 to CFLAGS 5 years ago
3 changed files with 203 additions and 49 deletions
Split View
  1. +3
    -3
      Makefile
  2. +2
    -2
      inc/hw_pinout.h
  3. +198
    -44
      src/main.c

+ 3
- 3
Makefile View File

@ -8,7 +8,7 @@ LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
PROJECTNAME=template
PROJECTNAME = template
SOURCES := main.c hw_pinout.c
GECKO_SDK_PATH := lib/GeckoSDK
@ -36,9 +36,9 @@ VPATH = .:src:$(EMLIB_SRC_PATH):$(EMLIB_DEVICE_PATH):$(EFM_DEVICE_PATH)/Source
INCLUDE_DIRS := inc $(EFM_DEVICE_PATH)/Include $(EMLIB_PATH)/inc \
$(CMSIS_PATH)/Include
CFLAGS := -Wall -Wextra -mcpu=cortex-m3 -mthumb \
CFLAGS := -O2 -std=c99 -Wall -Wextra -mcpu=cortex-m3 -mthumb \
-mfix-cortex-m3-ldrd -ffunction-sections \
-fdata-sections -fomit-frame-pointer -std=c99 \
-fdata-sections -fomit-frame-pointer \
-DEFM32TG110F32 \
$(addprefix -I, $(INCLUDE_DIRS))


+ 2
- 2
inc/hw_pinout.h View File

@ -4,12 +4,12 @@
#include <stdint.h>
typedef struct {
uint32_t port;
uint32_t port;
uint32_t pin;
} pinout_t;
enum {
LED1,
LED1,
LED2,
LED3,
LED4,


+ 198
- 44
src/main.c View File

@ -5,33 +5,26 @@
#include "em_cmu.h"
#include "hw_pinout.h"
volatile uint32_t msTicks; /* counts 1ms timeTicks */
#define ARRAYLEN(a) (sizeof(a) / sizeof(a[0]))
void Delay(uint32_t dlyTicks);
volatile uint32_t msTicks; /* counts 1ms timeTicks */
static void delay(uint32_t dlyTicks);
void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay()*/
msTicks++; /* increment counter necessary in delay()*/
}
void Delay(uint32_t dlyTicks)
static void delay(uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks) ;
}
uint32_t curTicks = msTicks;
void Blink(uint32_t port,uint32_t pin, uint32_t dlyTicks)
{
GPIO_PinOutToggle(port, pin);
Delay(dlyTicks);
GPIO_PinOutToggle(port, pin);
Delay(dlyTicks);
while ((msTicks - curTicks) < dlyTicks)
/* do nothing */;
}
int gpio_init(void)
static int gpio_init(void)
{
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPIO, true);
@ -47,45 +40,206 @@ int gpio_init(void)
}
int leds[] = {
static int leds[] = {
LED2,
LED4,
LED1,
LED4,
LED3,
};
int main()
static void debounce(void)
{
int currled=0;
CHIP_Init();
do {
delay(100);
} while (!GPIO_PinInGet(pins[USR1].port, pins[USR1].pin));
}
// Set systick to 1ms interval
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1);
gpio_init();
static void clear(void)
{
unsigned int i;
while(1)
{
pinout_t led = pins[leds[currled]];
while (!GPIO_PinInGet(pins[USR2].port, pins[USR2].pin))
{
GPIO_PinOutToggle(pins[LED1].port, pins[LED1].pin);
GPIO_PinOutToggle(pins[LED2].port, pins[LED2].pin);
GPIO_PinOutToggle(pins[LED3].port, pins[LED3].pin);
GPIO_PinOutToggle(pins[LED4].port, pins[LED4].pin);
Delay(500);
}
for (i = 0; i < ARRAYLEN(leds); i++) {
pinout_t led = pins[leds[i]];
GPIO_PinOutClear(led.port, led.pin);
}
}
static void setall(void)
{
unsigned int i;
for (i = 0; i < ARRAYLEN(leds); i++) {
pinout_t led = pins[leds[i]];
GPIO_PinOutSet(led.port, led.pin);
}
}
static void alllit(void)
{
setall();
while (GPIO_PinInGet(pins[USR1].port, pins[USR1].pin))
/* do nothing */;
}
static void circle(void)
{
unsigned int currled = 0;
clear();
while (GPIO_PinInGet(pins[USR1].port, pins[USR1].pin)) {
pinout_t led = pins[leds[currled++]];
currled %= ARRAYLEN(leds);
GPIO_PinOutSet(led.port, led.pin);
delay(100);
GPIO_PinOutClear(led.port, led.pin);
}
}
static void circle2(void)
{
unsigned int currled = 0;
clear();
while (GPIO_PinInGet(pins[USR1].port, pins[USR1].pin)) {
pinout_t led = pins[leds[currled++]];
currled %= ARRAYLEN(leds);
if (!GPIO_PinInGet(pins[USR1].port, pins[USR1].pin))
{
Blink(led.port, led.pin, 500);
GPIO_PinOutToggle(led.port, led.pin);
delay(100);
}
}
}else{
currled = (currled + 1) % 4;
static void freqs(void)
{
unsigned int state = 0;
unsigned int led = 0;
clear();
while (GPIO_PinInGet(pins[USR1].port, pins[USR1].pin)) {
state++;
GPIO_PinOutToggle(pins[led].port, pins[led].pin);
if (state % 2 == 0)
GPIO_PinOutToggle(pins[(led + 1) % ARRAYLEN(leds)].port, pins[(led + 1) % ARRAYLEN(leds)].pin);
if (state % 4 == 0)
GPIO_PinOutToggle(pins[(led + 2) % ARRAYLEN(leds)].port, pins[(led + 2) % ARRAYLEN(leds)].pin);
if (state % 8 == 0)
GPIO_PinOutToggle(pins[(led + 3) % ARRAYLEN(leds)].port, pins[(led + 3) % ARRAYLEN(leds)].pin);
delay(50);
state %= 64;
if (state == 0)
led = (led + 1) % ARRAYLEN(leds);
}
}
Blink(led.port, led.pin, 500);
static void heartbeat(void)
{
unsigned int i = 0;
clear();
while (GPIO_PinInGet(pins[USR1].port, pins[USR1].pin)) {
i++;
if (i % 10 == 0)
setall();
if (i % 11 == 0)
clear();
if (i % 12 == 0)
setall();
if (i % 13 == 0) {
clear();
i = 0;
}
delay(100);
}
}
return 0;
};
static void sos(void)
{
unsigned int i = 0;
clear();
while (GPIO_PinInGet(pins[USR1].port, pins[USR1].pin)) {
if (i == 0)
setall();
if (i == 1)
clear();
if (i == 2)
setall();
if (i == 3)
clear();
if (i == 4)
setall();
if (i == 5)
clear();
if (i == 6)
setall();
if (i == 9)
clear();
if (i == 10)
setall();
if (i == 13)
clear();
if (i == 14)
setall();
if (i == 17)
clear();
if (i == 18)
setall();
if (i == 19)
clear();
if (i == 20)
setall();
if (i == 21)
clear();
if (i == 22)
setall();
if (i == 23)
clear();
i++;
if (i == 32)
i = 0;
delay(100);
}
}
static void off(void)
{
clear();
while (GPIO_PinInGet(pins[USR1].port, pins[USR1].pin)) {
delay(50);
}
}
int main(void)
{
CHIP_Init();
// Set systick to 1ms interval
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000))
while (1);
gpio_init();
while (1) {
alllit();
debounce();
circle();
debounce();
circle2();
debounce();
freqs();
debounce();
heartbeat();
debounce();
sos();
debounce();
off();
debounce();
}
__builtin_unreachable();
}

Loading…
Cancel
Save