chore: blinky
This commit is contained in:
49
src/main.c
49
src/main.c
@@ -1,31 +1,42 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "rtl8710bx.h"
|
||||
|
||||
extern uint32_t DiagPrintf(const char *fmt, ...)
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
#define printf DiagPrintf
|
||||
|
||||
// GPIO direction register @ 0x1004 (from GPIO_Direction: 12 * port + 0x40000000
|
||||
// + 0x1000 + 4) For interrupt control: 0x1030: Interrupt enable register
|
||||
// 0x1038: Interrupt trigger type
|
||||
// 0x103C: Interrupt polarity
|
||||
// 0x1048: Interrupt debounce
|
||||
|
||||
#define PERIPH_BASE 0x40000000
|
||||
// 12 * port_number(0) + PERIPH_BASE + 0x1000
|
||||
#define PORT_A_BASE (PERIPH_BASE + 0x1000)
|
||||
|
||||
#define GPIOA_DIR (*(volatile uint32_t *)(PORT_A_BASE + 0x4))
|
||||
#define GPIOA (*(volatile uint32_t *)(PORT_A_BASE + 0x0))
|
||||
static inline void delay_cycles(unsigned int count) {
|
||||
__asm volatile(
|
||||
"1: \n"
|
||||
" subs %[count], %[count], #1 \n"
|
||||
" bne 1b \n"
|
||||
: [count] "+r"(count)
|
||||
:
|
||||
: "cc");
|
||||
}
|
||||
static inline void delay_ms(unsigned int ms) {
|
||||
for (unsigned int i = 0; i < ms; i++) {
|
||||
delay_cycles(15625); // 62500/4 cycles
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("hello from main\n");
|
||||
// while (1) {
|
||||
// __asm("nop");
|
||||
// }
|
||||
|
||||
GPIOA_DIR |= (1 << 0);
|
||||
PERI_ON->SOC_PERI_FUNC1_EN |= BIT_PERI_GPIO_EN;
|
||||
PERI_ON->PESOC_CLK_CTRL |= APBPeriph_GPIO_CLOCK;
|
||||
// branchless
|
||||
PINMUX_Config_BL(_PA_0, PINMUX_FN_GPIO);
|
||||
//
|
||||
PINMUX_Config(_PA_0, PINMUX_FN_GPIO);
|
||||
PINMUX_ConfigPadPull(_PA_0, GPIO_PuPd_DOWN);
|
||||
GPIOA->DDR |= (1 << 0);
|
||||
|
||||
while (1) {
|
||||
GPIOA ^= (1 << 0);
|
||||
for (volatile int i = 0; i < 100000; i++);
|
||||
GPIOA->DR |= (1 << 0);
|
||||
delay_ms(2000);
|
||||
GPIOA->DR &= ~(1 << 0);
|
||||
delay_ms(2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user