From e0bc7fae75b59324764abf4680a065caddcc70c2 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 31 Jan 2016 18:55:17 +0100 Subject: add rocket.initialize() function for initial MCU and peripheral setup --- src/main.cc | 19 +------------------ src/system.cc | 19 +++++++++++++++++++ src/system.h | 12 ++++++++---- 3 files changed, 28 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/main.cc b/src/main.cc index 5fa0c0d..5afa6d7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,7 +1,3 @@ -#include -#include -#include -#include #include #include "display.h" @@ -27,23 +23,10 @@ int main (void) test.length = 2*8; test.data = anim_data; - // disable ADC to save power - PRR |= _BV(PRADC); - - // dito - wdt_disable(); - - // Enable pull-ups on PC3 and PC7 (button pins) - PORTC |= _BV(PC3) | _BV(PC7); + rocket.initialize(); display.show(&ohai); - display.enable(); - modem.enable(); - storage.enable(); - - sei(); - while (1) { // nothing to do here, go to idle to save power SMCR = _BV(SE); diff --git a/src/system.cc b/src/system.cc index 15ee0b9..a192b24 100644 --- a/src/system.cc +++ b/src/system.cc @@ -6,6 +6,7 @@ #include "display.h" #include "modem.h" +#include "storage.h" #include "system.h" #define SHUTDOWN_THRESHOLD 2048 @@ -16,6 +17,24 @@ extern animation_t ohai; uint8_t disp_buf[128]; +void System::initialize() +{ + // disable ADC to save power + PRR |= _BV(PRADC); + + // dito + wdt_disable(); + + // Enable pull-ups on PC3 and PC7 (button pins) + PORTC |= _BV(PC3) | _BV(PC7); + + display.enable(); + modem.enable(); + storage.enable(); + + sei(); +} + void System::loop() { static uint8_t i = 0; diff --git a/src/system.h b/src/system.h index b36e348..7c0ab80 100644 --- a/src/system.h +++ b/src/system.h @@ -1,7 +1,3 @@ -#include -#include -#include -#include #include #define SHUTDOWN_THRESHOLD 2048 @@ -17,6 +13,14 @@ class System { public: System() { want_shutdown = 0; }; + /** + * Initial MCU setup. Turns off unused peripherals to save power + * and configures the button pins. Also configures all other pins + * and peripherals using the enable function of their respective + * classes. Turns on interrupts once that's done. + */ + void initialize(void); + /** * System idle loop. Checks for button presses, handles * standby/resume, reads data from the Modem and updates the Display. -- cgit v1.2.3