From 39a17c99b988086396388a942889c78b84ad6891 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Tue, 28 Sep 2021 13:42:08 -0400 Subject: [PATCH] overdue refactor: compile all watch modules separately --- make.mk | 11 +++++++++++ watch-library/hal/include/hal_calendar.h | 0 watch-library/hal/src/hal_calendar.c | 0 watch-library/watch/watch.c | 12 ------------ watch-library/watch/watch_adc.c | 2 ++ watch-library/watch/watch_adc.h | 5 +++++ watch-library/watch/watch_app.h | 3 +++ watch-library/watch/watch_buzzer.c | 2 ++ watch-library/watch/watch_buzzer.h | 5 +++++ watch-library/watch/watch_deepsleep.c | 2 ++ watch-library/watch/watch_deepsleep.h | 5 +++++ watch-library/watch/watch_extint.c | 2 ++ watch-library/watch/watch_extint.h | 4 ++++ watch-library/watch/watch_gpio.c | 2 ++ watch-library/watch/watch_gpio.h | 5 +++++ watch-library/watch/watch_i2c.c | 4 +++- watch-library/watch/watch_i2c.h | 5 +++++ watch-library/watch/watch_led.c | 2 ++ watch-library/watch/watch_led.h | 5 +++++ watch-library/watch/watch_private.c | 1 + watch-library/watch/watch_private.h | 8 ++++++++ watch-library/watch/watch_rtc.c | 2 ++ watch-library/watch/watch_rtc.h | 4 ++++ watch-library/watch/watch_slcd.c | 2 ++ watch-library/watch/watch_slcd.h | 5 +++++ watch-library/watch/watch_uart.c | 1 + watch-library/watch/watch_uart.h | 5 +++++ 27 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 watch-library/hal/include/hal_calendar.h create mode 100644 watch-library/hal/src/hal_calendar.c diff --git a/make.mk b/make.mk index ae32f2d..299d9d3 100644 --- a/make.mk +++ b/make.mk @@ -71,6 +71,17 @@ SRCS += \ $(TOP)/watch-library/main.c \ $(TOP)/watch-library/startup_saml22.c \ $(TOP)/watch-library/hw/driver_init.c \ + $(TOP)/watch-library/watch/watch_rtc.c \ + $(TOP)/watch-library/watch/watch_slcd.c \ + $(TOP)/watch-library/watch/watch_extint.c \ + $(TOP)/watch-library/watch/watch_led.c \ + $(TOP)/watch-library/watch/watch_buzzer.c \ + $(TOP)/watch-library/watch/watch_adc.c \ + $(TOP)/watch-library/watch/watch_gpio.c \ + $(TOP)/watch-library/watch/watch_i2c.c \ + $(TOP)/watch-library/watch/watch_uart.c \ + $(TOP)/watch-library/watch/watch_deepsleep.c \ + $(TOP)/watch-library/watch/watch_private.c \ $(TOP)/watch-library/watch/watch.c \ $(TOP)/watch-library/hal/src/hal_atomic.c \ $(TOP)/watch-library/hal/src/hal_delay.c \ diff --git a/watch-library/hal/include/hal_calendar.h b/watch-library/hal/include/hal_calendar.h new file mode 100644 index 0000000..e69de29 diff --git a/watch-library/hal/src/hal_calendar.c b/watch-library/hal/src/hal_calendar.c new file mode 100644 index 0000000..e69de29 diff --git a/watch-library/watch/watch.c b/watch-library/watch/watch.c index 6196b1f..de7160c 100644 --- a/watch-library/watch/watch.c +++ b/watch-library/watch/watch.c @@ -24,18 +24,6 @@ #include "watch.h" -#include "watch_rtc.c" -#include "watch_slcd.c" -#include "watch_extint.c" -#include "watch_led.c" -#include "watch_buzzer.c" -#include "watch_adc.c" -#include "watch_gpio.c" -#include "watch_i2c.c" -#include "watch_uart.c" -#include "watch_deepsleep.c" -#include "watch_private.c" - bool battery_is_low = false; // receives interrupts from MCLK, OSC32KCTRL, OSCCTRL, PAC, PM, SUPC and TAL, whatever that is. diff --git a/watch-library/watch/watch_adc.c b/watch-library/watch/watch_adc.c index 490a49b..90980a8 100644 --- a/watch-library/watch/watch_adc.c +++ b/watch-library/watch/watch_adc.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "watch_adc.h" + void _watch_sync_adc() { while (ADC->SYNCBUSY.reg); } diff --git a/watch-library/watch/watch_adc.h b/watch-library/watch/watch_adc.h index b49f130..c9b6ad2 100644 --- a/watch-library/watch/watch_adc.h +++ b/watch-library/watch/watch_adc.h @@ -21,8 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_ADC_H_INCLUDED +#define _WATCH_ADC_H_INCLUDED ////< @file watch_adc.h +#include "watch.h" + /** @addtogroup adc Analog Input * @brief This section covers functions related to the SAM L22's analog-to-digital converter, * as well as configuring and reading values from the five analog-capable pins on the @@ -103,3 +107,4 @@ void watch_disable_analog_input(const uint8_t pin); void watch_disable_adc(); /// @} +#endif diff --git a/watch-library/watch/watch_app.h b/watch-library/watch/watch_app.h index fd7ea70..00a6a61 100644 --- a/watch-library/watch/watch_app.h +++ b/watch-library/watch/watch_app.h @@ -21,6 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_APP_H_INCLUDED +#define _WATCH_APP_H_INCLUDED ////< @file watch_app.h /** @addtogroup app Application Framework @@ -103,3 +105,4 @@ void app_prepare_for_sleep(); void app_wake_from_sleep(); /// @} +#endif diff --git a/watch-library/watch/watch_buzzer.c b/watch-library/watch/watch_buzzer.c index 9cb3739..007a44c 100644 --- a/watch-library/watch/watch_buzzer.c +++ b/watch-library/watch/watch_buzzer.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "watch_buzzer.h" + inline void watch_enable_buzzer() { if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { _watch_enable_tcc(); diff --git a/watch-library/watch/watch_buzzer.h b/watch-library/watch/watch_buzzer.h index 995e059..e15657b 100644 --- a/watch-library/watch/watch_buzzer.h +++ b/watch-library/watch/watch_buzzer.h @@ -21,8 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_BUZZER_H_INCLUDED +#define _WATCH_BUZZER_H_INCLUDED ////< @file watch_buzzer.h +#include "watch.h" + /** @addtogroup buzzer Buzzer * @brief This section covers functions related to the piezo buzzer embedded in the F-91W's back plate. */ @@ -157,3 +161,4 @@ void watch_buzzer_play_note(BuzzerNote note, uint16_t duration_ms); extern const uint16_t NotePeriods[108]; /// @} +#endif diff --git a/watch-library/watch/watch_deepsleep.c b/watch-library/watch/watch_deepsleep.c index 4294b66..c83254e 100644 --- a/watch-library/watch/watch_deepsleep.c +++ b/watch-library/watch/watch_deepsleep.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "watch_extint.h" + // this warning only appears when you `make BOARD=OSO-SWAT-A1-02`. it's annoying, // but i'd rather have it warn us at build-time than fail silently at run-time. // besides, no one but me really has any of these boards anyway. diff --git a/watch-library/watch/watch_deepsleep.h b/watch-library/watch/watch_deepsleep.h index dc8724d..3dc428d 100644 --- a/watch-library/watch/watch_deepsleep.h +++ b/watch-library/watch/watch_deepsleep.h @@ -21,8 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_DEEPSLEEP_H_INCLUDED +#define _WATCH_DEEPSLEEP_H_INCLUDED ////< @file watch_deepsleep.h +#include "watch.h" + // These are declared in watch_rtc.c. extern ext_irq_cb_t btn_alarm_callback; extern ext_irq_cb_t a2_callback; @@ -115,3 +119,4 @@ void watch_enter_shallow_sleep(char *message); */ void watch_enter_deep_sleep(); /// @} +#endif diff --git a/watch-library/watch/watch_extint.c b/watch-library/watch/watch_extint.c index f2bad94..dcaa0d8 100644 --- a/watch-library/watch/watch_extint.c +++ b/watch-library/watch/watch_extint.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "watch_extint.h" + void watch_enable_external_interrupts() { // Configure EIC to use GCLK3 (the 32.768 kHz crystal) hri_gclk_write_PCHCTRL_reg(GCLK, EIC_GCLK_ID, GCLK_PCHCTRL_GEN_GCLK3_Val | (1 << GCLK_PCHCTRL_CHEN_Pos)); diff --git a/watch-library/watch/watch_extint.h b/watch-library/watch/watch_extint.h index 9c81053..758fe8b 100644 --- a/watch-library/watch/watch_extint.h +++ b/watch-library/watch/watch_extint.h @@ -21,8 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_EXTINT_H_INCLUDED +#define _WATCH_EXTINT_H_INCLUDED ////< @file watch_extint.h +#include "watch.h" #include "hal_ext_irq.h" /** @addtogroup buttons Buttons & External Interrupts @@ -78,3 +81,4 @@ void watch_register_button_callback(const uint8_t pin, ext_irq_cb_t callback); __attribute__((deprecated("Use watch_enable_external_interrupts instead"))) void watch_enable_buttons(); /// @} +#endif diff --git a/watch-library/watch/watch_gpio.c b/watch-library/watch/watch_gpio.c index a9bc139..b37d009 100644 --- a/watch-library/watch/watch_gpio.c +++ b/watch-library/watch/watch_gpio.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "watch_gpio.h" + void watch_enable_digital_input(const uint8_t pin) { gpio_set_pin_direction(pin, GPIO_DIRECTION_IN); gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF); diff --git a/watch-library/watch/watch_gpio.h b/watch-library/watch/watch_gpio.h index 640686e..fc43642 100644 --- a/watch-library/watch/watch_gpio.h +++ b/watch-library/watch/watch_gpio.h @@ -21,8 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_GPIO_H_INCLUDED +#define _WATCH_GPIO_H_INCLUDED ////< @file watch_gpio.h +#include "watch.h" + /** @addtogroup gpio Digital Input and Output * @brief This section covers functions related to general-purpose input and output signals. */ @@ -69,3 +73,4 @@ void watch_disable_digital_output(const uint8_t pin); */ void watch_set_pin_level(const uint8_t pin, const bool level); /// @} +#endif diff --git a/watch-library/watch/watch_i2c.c b/watch-library/watch/watch_i2c.c index 385d9d0..d2cf474 100644 --- a/watch-library/watch/watch_i2c.c +++ b/watch-library/watch/watch_i2c.c @@ -22,7 +22,9 @@ * SOFTWARE. */ - struct io_descriptor *I2C_0_io; +#include "watch_i2c.h" + +struct io_descriptor *I2C_0_io; void watch_enable_i2c() { I2C_0_init(); diff --git a/watch-library/watch/watch_i2c.h b/watch-library/watch/watch_i2c.h index 7ac05c1..65df49b 100644 --- a/watch-library/watch/watch_i2c.h +++ b/watch-library/watch/watch_i2c.h @@ -21,8 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_I2C_H_INCLUDED +#define _WATCH_I2C_H_INCLUDED ////< @file watch_i2c.h +#include "watch.h" + /** @addtogroup i2c I2C Controller Driver * @brief This section covers functions related to the SAM L22's built-I2C driver, including * configuring the I2C bus, putting values directly on the bus and reading data from @@ -99,3 +103,4 @@ uint32_t watch_i2c_read24(int16_t addr, uint8_t reg); */ uint32_t watch_i2c_read32(int16_t addr, uint8_t reg); /// @} +#endif diff --git a/watch-library/watch/watch_led.c b/watch-library/watch/watch_led.c index 7b18945..1348c97 100644 --- a/watch-library/watch/watch_led.c +++ b/watch-library/watch/watch_led.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "watch_led.h" + void watch_enable_leds() { if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { _watch_enable_tcc(); diff --git a/watch-library/watch/watch_led.h b/watch-library/watch/watch_led.h index 0927e71..2b9dead 100644 --- a/watch-library/watch/watch_led.h +++ b/watch-library/watch/watch_led.h @@ -21,8 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_LED_H_INCLUDED +#define _WATCH_LED_H_INCLUDED ////< @file watch_led.h +#include "watch.h" + /** @addtogroup led LED Control * @brief This section covers functions related to the bi-color red/green LED mounted behind the LCD. * @details The SAM L22 is an exceedingly power efficient chip, whereas the LED's are relatively power- @@ -86,3 +90,4 @@ void watch_enable_led(bool unused); __attribute__((deprecated("Use watch_disable_leds instead"))) void watch_disable_led(bool unused); /// @} +#endif diff --git a/watch-library/watch/watch_private.c b/watch-library/watch/watch_private.c index dc70f4c..270208d 100644 --- a/watch-library/watch/watch_private.c +++ b/watch-library/watch/watch_private.c @@ -22,6 +22,7 @@ * SOFTWARE. */ +#include "watch_private.h" #include "tusb.h" void _watch_init() { diff --git a/watch-library/watch/watch_private.h b/watch-library/watch/watch_private.h index abee085..8045e43 100644 --- a/watch-library/watch/watch_private.h +++ b/watch-library/watch/watch_private.h @@ -21,10 +21,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_PRIVATE_H_INCLUDED +#define _WATCH_PRIVATE_H_INCLUDED + +#include "watch.h" /// Called by main.c while setting up the app. You should not call this from your app. void _watch_init(); +/// Initializes the real-time clock peripheral. +void _watch_rtc_init(); + /// Called by buzzer and LED setup functions. You should not call this from your app. void _watch_enable_tcc(); @@ -33,3 +40,4 @@ void _watch_disable_tcc(); /// Called by main.c if plugged in to USB. You should not call this from your app. void _watch_enable_usb(); +#endif diff --git a/watch-library/watch/watch_rtc.c b/watch-library/watch/watch_rtc.c index 43cff47..0974c79 100644 --- a/watch-library/watch/watch_rtc.c +++ b/watch-library/watch/watch_rtc.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "watch_rtc.h" + ext_irq_cb_t tick_callback; ext_irq_cb_t alarm_callback; ext_irq_cb_t btn_alarm_callback; diff --git a/watch-library/watch/watch_rtc.h b/watch-library/watch/watch_rtc.h index a224875..71f555a 100644 --- a/watch-library/watch/watch_rtc.h +++ b/watch-library/watch/watch_rtc.h @@ -21,8 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_RTC_H_INCLUDED +#define _WATCH_RTC_H_INCLUDED ////< @file watch_rtc.h +#include "watch.h" #include "hpl_calendar.h" /** @addtogroup rtc Real-Time Clock @@ -122,3 +125,4 @@ __attribute__((deprecated("Use the watch_rtc_get_date_time function instead"))) void watch_get_date_time(struct calendar_date_time *date_time); /// @} +#endif diff --git a/watch-library/watch/watch_slcd.c b/watch-library/watch/watch_slcd.c index 7210713..ba9d12b 100644 --- a/watch-library/watch/watch_slcd.c +++ b/watch-library/watch/watch_slcd.c @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "watch_slcd.h" + ////////////////////////////////////////////////////////////////////////////////////////// // Segmented Display diff --git a/watch-library/watch/watch_slcd.h b/watch-library/watch/watch_slcd.h index efef99a..4f5a617 100644 --- a/watch-library/watch/watch_slcd.h +++ b/watch-library/watch/watch_slcd.h @@ -21,8 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_SLCD_H_INCLUDED +#define _WATCH_SLCD_H_INCLUDED ////< @file watch_slcd.h +#include "watch.h" + /** @addtogroup slcd Segment LCD Display * @brief This section covers functions related to the Segment LCD display driver, which is responsible * for displaying strings of characters and indicators on the main watch display. @@ -100,3 +104,4 @@ void watch_clear_indicator(WatchIndicatorSegment indicator); void watch_clear_all_indicators(); /// @} +#endif diff --git a/watch-library/watch/watch_uart.c b/watch-library/watch/watch_uart.c index 3d97803..d35533d 100644 --- a/watch-library/watch/watch_uart.c +++ b/watch-library/watch/watch_uart.c @@ -50,6 +50,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "watch_uart.h" #include "peripheral_clk_config.h" void watch_enable_debug_uart(uint32_t baud) { diff --git a/watch-library/watch/watch_uart.h b/watch-library/watch/watch_uart.h index 3c4f7ae..3e98bd3 100644 --- a/watch-library/watch/watch_uart.h +++ b/watch-library/watch/watch_uart.h @@ -21,8 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#ifndef _WATCH_UART_H_INCLUDED +#define _WATCH_UART_H_INCLUDED ////< @file watch_uart.h +#include "watch.h" + /** @addtogroup debug Debug UART * @brief This section covers functions related to the debug UART, available on * pin D1 of the 9-pin connector. @@ -51,3 +55,4 @@ void watch_debug_putc(char c); __attribute__((deprecated("Use printf to log debug messages over USB."))) void watch_debug_puts(char *s); /// @} +#endif