From 6029630643335ebe7dbba2da8e7bf2b5f7a434f9 Mon Sep 17 00:00:00 2001 From: Nils Faerber Date: Sun, 5 May 2013 00:31:14 +0200 Subject: [PATCH] Start support for the accelerometer, change text position for clock setup --- metawatch/mw_acc.c | 71 +++++++++++++++++++++++++++++ metawatch/mw_acc.h | 109 ++++++++++++++++++++++++++++++++++++++++++++ ui/oswald_screens.c | 8 ++-- 3 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 metawatch/mw_acc.c create mode 100644 metawatch/mw_acc.h diff --git a/metawatch/mw_acc.c b/metawatch/mw_acc.c new file mode 100644 index 0000000..270f246 --- /dev/null +++ b/metawatch/mw_acc.c @@ -0,0 +1,71 @@ +#include +#include +#include + +#include "mw_main.h" + +#include "mw_acc.h" + +void mw_init_acc_i2c(void) +{ + /* enable reset before configuration */ + ACCELEROMETER_CTL1 |= UCSWRST; + + /* configure as master using smclk / 40 = 399.5 kHz */ + ACCELEROMETER_CTL0 = UCMST + UCMODE_3 + UCSYNC; + ACCELEROMETER_CTL1 = UCSSEL__SMCLK + UCSWRST; + ACCELEROMETER_BR0 = 42; + + ACCELEROMETER_BR1 = 0; + ACCELEROMETER_I2CSA = KIONIX_DEVICE_ADDRESS; + + /* release reset */ + ACCELEROMETER_CTL1 &= ~UCSWRST; +} + +/* + * DMA2 = SPI for LCD + */ +static void mw_acc_i2c_write_byte(uint8_t byte) +{ + ACCELEROMETER_TXBUF = byte; + while ((ACCELEROMETER_CTL1 & ACCELEROMETER_IFG) == 0) + nop(); +} + +/* OK this is polling write, but data is small and 400kHz I2C, it should "just work" :) */ +void mw_acc_i2c_write(const uint8_t addr, const void *data, const uint8_t len) +{ + int i; + + if (len == 0) { + return; + } + + while (UCB1STAT & UCBBUSY) + nop(); + + /* + * setup for write and send the start condition + */ + ACCELEROMETER_IFG = 0; + ACCELEROMETER_CTL1 |= UCTR + UCTXSTT; + while (!(ACCELEROMETER_IFG & UCTXIFG)) + nop(); + + /* + * clear transmit interrupt flag, + * send the register address + */ + ACCELEROMETER_IFG = 0; + + mw_acc_i2c_write_byte(addr); + + for (i=0; ipos == 6 && sdata->on) || sdata->pos != 6) { if (OswaldClk.clk24hr) { - oswald_write_character(2, 76, FONT_DROID8x12, 'x'); + oswald_write_character(2, 76, FONT_6x9, 'x'); } else { - oswald_write_character(2, 76, FONT_DROID8x12, '_'); + oswald_write_character(2, 76, FONT_6x9, '_'); } } oswald_write_string(15, 73, FONT_DROID8x12, "24hr"); if ((sdata->pos == 7 && sdata->on) || sdata->pos != 7) { if (OswaldClk.day_first) { - oswald_write_character(2, 87, FONT_DROID8x12, 'x'); + oswald_write_character(2, 86, FONT_6x9, 'x'); } else { - oswald_write_character(2, 87, FONT_DROID8x12, '_'); + oswald_write_character(2, 86, FONT_6x9, '_'); } } oswald_write_string(15, 83, FONT_DROID8x12, "dd.mm. mm/dd"); -- 2.39.2