The unified diff between revisions [24d5b9f4..] and [4f22e7ef..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'main.c'
# # old_revision [24d5b9f4dff9135787b198fe1127d9c1e3326b9c] # new_revision [4f22e7ef7d3064e3b51a5b868a4722f3f13c747b] # # patch "main.c" # from [8284ca89102568b2ae6f26e057ab296621f87e6a] # to [dca584ff21fb033c2abff13cfb14db9c8c2c93c2] # ============================================================ --- main.c 8284ca89102568b2ae6f26e057ab296621f87e6a +++ main.c dca584ff21fb033c2abff13cfb14db9c8c2c93c2 @@ -18,15 +18,20 @@ #define SCS (*((volatile unsigned int *) 0xe01fc1a0)) +#define BUTTON_PRESSED (!((FP0XVAL) & 0x00010000)) void init_pins(void) { - PINSEL0 = 0x00a88055; /* P0.0 and P0.1 assigned to UART */ + PINSEL0 = 0x2a09a255; /* P0.0 and P0.1 assigned to UART */ /* P0.2 and P0.3 assigned to I2C */ + /* P0.4 and P0.6 assigned to CAP0.[12] */ /* P0.7 and P0.9 assigned to MAT2.[02] */ - /* P0.10 and P0.11 assigned to CAP1.[01] */ - PINSEL1 = 0x20000828; /* P0.21 and P0.30 assigned to MAT3.[03] */ - /* P0.17 and P0.18 assigned to CAP1.[23] */ + /* P0.8 assigned to UART1 */ + /* P0.12 and P0.13 assigned to MAT1.[01] */ + /* P0.14 assigned to SPI1 */ + + PINSEL1 = 0x00000540; /* P0.19 to P0.21 assigned to SPI1 */ + SCS = 1; FP0XDIR = 0x04000000; /* P0.26 is an output */ FP0XVAL = 0x0; @@ -180,6 +185,53 @@ void menu_handler(void); void menu_handler(void); +void wait_for_button_pressed(bool target) +{ + bool pressed; + + led_set(!target); + + /* Very crude debouncing */ + timer_delay_ms(100); + + target = target ? TRUE:FALSE; + + do { + pressed = BUTTON_PRESSED; + } while (pressed != target); + led_set(pressed); +} + +void calibrate_escs() +{ + wait_for_button_pressed(0); + + putstr("Calibration mode\r\n"); + + wait_for_button_pressed(1); + wait_for_button_pressed(0); + + set_thrust(0, 1.0); + set_thrust(1, 1.0); + set_thrust(2, 1.0); + set_thrust(3, 1.0); + putstr("Max throttle set\r\n"); + + wait_for_button_pressed(1); + wait_for_button_pressed(0); + + set_thrust(0, 0.0); + set_thrust(1, 0.0); + set_thrust(2, 0.0); + set_thrust(3, 0.0); + putstr("Zero throttle set\r\n"); + + wait_for_button_pressed(1); + wait_for_button_pressed(0); + + putstr("Exit calibration mode\r\n"); +} + int main(void) { init_interrupt(); init_uart(); @@ -196,6 +248,9 @@ int main(void) { putstr("Your entire life has been a mathematical error... a mathematical error I'm about to correct!\r\n"); + if (BUTTON_PRESSED) + calibrate_escs(); + putstr("prompt> "); timer_delay_ms(1000);