mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-14 20:03:44 +00:00
62d0e598d4
* update submodule to latest GSG modifications * build: fix delay function * update submodule to include praline fix * fix dep to rebuild/reinclude hackrf_usb_ram.bin
68 lines
1.3 KiB
C
68 lines
1.3 KiB
C
#include "gpio_lpc.h"
|
|
#include "gpio.h"
|
|
#include "delay.h"
|
|
|
|
typedef enum {
|
|
LED1 = 0,
|
|
LED2 = 1,
|
|
LED3 = 2,
|
|
LED4 = 3,
|
|
} led_t;
|
|
|
|
/* GPIO Output PinMux */
|
|
static struct gpio gpio_led[] = {
|
|
GPIO(2, 1),
|
|
GPIO(2, 2),
|
|
GPIO(2, 8),
|
|
#ifdef RAD1O
|
|
GPIO(5, 26),
|
|
#endif
|
|
};
|
|
|
|
void delay(uint32_t duration) {
|
|
while (duration--) {
|
|
/* cannot be optimized out */
|
|
__asm__ volatile("nop");
|
|
}
|
|
}
|
|
|
|
void delay_us_at_mhz(uint32_t us, uint32_t mhz) {
|
|
/* overflow-safe multiply */
|
|
uint64_t cycles64 = (uint64_t)us * (uint64_t)mhz;
|
|
if (cycles64 > UINT32_MAX) {
|
|
cycles64 = UINT32_MAX;
|
|
}
|
|
delay((uint32_t)cycles64);
|
|
}
|
|
|
|
/* The application M0 core runs from BASE_M4_CLK at 200MHz. */
|
|
void delay_us(uint32_t us) {
|
|
delay_us_at_mhz(us, 200);
|
|
}
|
|
|
|
void delay_ms(uint32_t ms) {
|
|
delay_us_at_mhz(ms * 1000, 200);
|
|
}
|
|
|
|
void led_on(const led_t led) {
|
|
gpio_set(&gpio_led[led]);
|
|
}
|
|
|
|
void led_off(const led_t led) {
|
|
gpio_clear(&gpio_led[led]);
|
|
}
|
|
|
|
void halt_and_flash(const uint32_t duration) {
|
|
/* blink LED1, LED2, and LED3 */
|
|
while (1) {
|
|
led_on(LED1);
|
|
led_on(LED2);
|
|
led_on(LED3);
|
|
delay(duration);
|
|
led_off(LED1);
|
|
led_off(LED2);
|
|
led_off(LED3);
|
|
delay(duration);
|
|
}
|
|
}
|