Compare commits
No commits in common. "6f81461b2c929b0d5af5980f6c8341fb9cfb3fc7" and "bb32eb661467856faf9872097f39abee9fb342d5" have entirely different histories.
6f81461b2c
...
bb32eb6614
|
@ -5,7 +5,6 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "encoder.h"
|
||||
#include "systick.h"
|
||||
|
||||
|
@ -78,8 +77,8 @@ int encoder_speed() {
|
|||
int encoder_current_speed() {
|
||||
int dt = ticks_ms(tick - speed_ticks[SPEED_AVG_NUM - 1].tick);
|
||||
if (dt > 200) {
|
||||
memmove(&speed_ticks[0], &speed_ticks[1], SPEED_AVG_NUM * sizeof speed_ticks[0]);
|
||||
speed_ticks[SPEED_AVG_NUM].tick = tick;
|
||||
printf("dt: %d", dt);
|
||||
return 0;
|
||||
}
|
||||
return 1000
|
||||
* (speed_ticks[SPEED_AVG_NUM-1].pos - speed_ticks[0].pos)
|
||||
|
|
68
main.c
68
main.c
|
@ -4,7 +4,6 @@
|
|||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "adc.h"
|
||||
#include "buttons.h"
|
||||
|
@ -32,8 +31,6 @@ static void erase_app(void);
|
|||
#endif
|
||||
|
||||
static void fast_reset(void);
|
||||
static void set_watchdog(int w);
|
||||
static void set_print_changes(int p);
|
||||
|
||||
static void sys_tick_setup() {
|
||||
systick_set_reload(rcc_ahb_frequency / SYSTICK_FREQUENCY - 1);
|
||||
|
@ -64,19 +61,6 @@ void erase_app() {
|
|||
}
|
||||
#endif
|
||||
|
||||
int watchdog = 0;
|
||||
int print_changes = 0;
|
||||
|
||||
void set_watchdog(int w) {
|
||||
watchdog = w;
|
||||
printf("watchdog: %d", watchdog);
|
||||
}
|
||||
|
||||
void set_print_changes(int p) {
|
||||
print_changes = p;
|
||||
printf("pos reporting: %d", print_changes);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
#if 0
|
||||
rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_84MHZ]);
|
||||
|
@ -102,20 +86,18 @@ int main(void) {
|
|||
|
||||
uint32_t last_tick = tick;
|
||||
int last_pos = 0;
|
||||
int watchdog = 1;
|
||||
uint32_t watchdog_counter = 0;
|
||||
int print_changes = 0;
|
||||
|
||||
while (tick < 5000 && !usb_connected()) {
|
||||
while (tick < 5000) {
|
||||
usbd_poll(g_usbd_dev);
|
||||
}
|
||||
|
||||
if (!usb_connected()) {
|
||||
if (!usb_got_reset()) {
|
||||
fast_reset();
|
||||
}
|
||||
|
||||
char cmd_buf[64];
|
||||
uint8_t cmd_len = 0;
|
||||
bool cmd = false;
|
||||
|
||||
while (1) {
|
||||
/* Handle control messages through the comms CDC */
|
||||
char buf[64];
|
||||
|
@ -135,37 +117,7 @@ int main(void) {
|
|||
}
|
||||
|
||||
for (char c; ringbuffer_get(comm_in_buf, (void *)&c, 1);) {
|
||||
if (cmd) {
|
||||
if (c == '\r' || c == '\n') {
|
||||
cmd_buf[cmd_len] = 0;
|
||||
|
||||
if (cmd_buf[0] == 'r' && cmd_len == 2 && (cmd_buf[1] == '0' || cmd_buf[1] == '1')) {
|
||||
set_print_changes(cmd_buf[1] == '1');
|
||||
} else if(cmd_buf[0] == 'w' && cmd_len == 2 && (cmd_buf[1] == '0' || cmd_buf[1] == '1')) {
|
||||
set_watchdog(cmd_buf[1] == '1');
|
||||
} else if (!strcmp(cmd_buf, "reset")) {
|
||||
fast_reset();
|
||||
}
|
||||
#if defined(BOOTLOADER)
|
||||
else if (!strcmp(cmd_buf, "flash")) {
|
||||
start_bootloader();
|
||||
} else if (!strcmp(cmd_buf, "erase")) {
|
||||
erase_app();
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
printf("unknown command: %s", cmd_buf);
|
||||
}
|
||||
cmd = false;
|
||||
} else if (cmd_len < sizeof cmd_buf - 1) {
|
||||
cmd_buf[cmd_len++] = c;
|
||||
}
|
||||
}
|
||||
else switch (c) {
|
||||
case '>':
|
||||
cmd = true;
|
||||
cmd_len = 0;
|
||||
break;
|
||||
switch (c) {
|
||||
case 'B': // Battery
|
||||
printf("%lu", (unsigned long)adc_bat_voltage());
|
||||
break;
|
||||
|
@ -179,10 +131,12 @@ int main(void) {
|
|||
printf("pos: %d %d", encoder_get(), encoder_current_speed());
|
||||
break;
|
||||
case 'r': // toggle reporting
|
||||
set_print_changes(!print_changes);
|
||||
print_changes = !print_changes;
|
||||
printf("pos reporting: %d", print_changes);
|
||||
break;
|
||||
case 'W': // toggle watchdog
|
||||
set_watchdog(!watchdog);
|
||||
watchdog = !watchdog;
|
||||
printf("watchdog: %d", watchdog);
|
||||
break;
|
||||
case 'S': // reStart
|
||||
fast_reset();
|
||||
|
@ -210,7 +164,7 @@ int main(void) {
|
|||
|
||||
/* Send replies */
|
||||
if ((buf_len = ringbuffer_peek(comm_out_buf, &buf[0], sizeof buf))) {
|
||||
if (!usb_connected() || usb_write_cdcacm(ACM_COMM, (void *)buf, buf_len, 1)) {
|
||||
if (usb_write_cdcacm(ACM_COMM, (void *)buf, buf_len, 1)) {
|
||||
ringbuffer_skip(comm_out_buf, buf_len);
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +172,7 @@ int main(void) {
|
|||
/* Send any available data to the NFC CDC */
|
||||
if (!ringbuffer_empty(uart_to_usb_buf)) {
|
||||
unsigned len = ringbuffer_peek(uart_to_usb_buf, &buf[0], sizeof buf);
|
||||
if (!usb_connected() || usb_write_cdcacm(ACM_NFC, &buf[0], len, 1)) {
|
||||
if (usb_write_cdcacm(ACM_NFC, &buf[0], len, 1)) {
|
||||
ringbuffer_skip(uart_to_usb_buf, len);
|
||||
}
|
||||
}
|
||||
|
|
16
usb.c
16
usb.c
|
@ -11,9 +11,6 @@
|
|||
|
||||
extern ringbuffer *usb_to_uart_buf, *comm_in_buf;
|
||||
|
||||
static void usb_reset_callback(void);
|
||||
static void usb_suspend_callback(void);
|
||||
|
||||
/* Number of serial devices we want to provide. */
|
||||
#define NUM_SERIAL 2
|
||||
|
||||
|
@ -43,7 +40,7 @@ static char const *usb_strings[] = {
|
|||
[3 + ACM_NFC] = "RFID",
|
||||
};
|
||||
|
||||
static int connected = 0;
|
||||
static int got_reset = 0;
|
||||
|
||||
usbd_device *g_usbd_dev;
|
||||
|
||||
|
@ -179,15 +176,11 @@ static void cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue) {
|
|||
}
|
||||
|
||||
void usb_reset_callback(void) {
|
||||
connected = 1;
|
||||
got_reset = 1;
|
||||
}
|
||||
|
||||
void usb_suspend_callback(void) {
|
||||
connected = 0;
|
||||
}
|
||||
|
||||
bool usb_connected(void) {
|
||||
return connected;
|
||||
bool usb_got_reset(void) {
|
||||
return got_reset;
|
||||
}
|
||||
|
||||
void usb_setup() {
|
||||
|
@ -344,7 +337,6 @@ void usb_reinit() {
|
|||
usbd_control_buffer, sizeof(usbd_control_buffer));
|
||||
|
||||
usbd_register_reset_callback(g_usbd_dev, &usb_reset_callback);
|
||||
usbd_register_suspend_callback(g_usbd_dev, &usb_suspend_callback);
|
||||
usbd_register_set_config_callback(g_usbd_dev, cdcacm_set_config);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user