void rtc_set_alarm(int h, int m) { int day = mc13783_read(MC13783_RTC_DAY); int tod = mc13783_read(MC13783_RTC_TIME); if (h*3600 + m*60 < tod) day++; mc13783_write(MC13783_RTC_DAY_ALARM, day); mc13783_write(MC13783_RTC_ALARM, h*3600 + m*60); }
/** Public APIs **/ void rtc_init(void) { /* only needs to be polled on startup */ if (mc13783_read(MC13783_INTERRUPT_STATUS1) & MC13783_TODAI) { alarm_start = true; mc13783_write(MC13783_INTERRUPT_STATUS1, MC13783_TODAI); } }
void INIT_ATTR mc13783_init(void) { /* Serial interface must have been initialized first! */ wakeup_init(&mc13783_svc_wake); mutex_init(&mc13783_spi_mutex); wakeup_init(&mc13783_spi_wake); /* Enable the PMIC SPI module */ spi_enable_module(&mc13783_spi); /* Mask any PMIC interrupts for now - modules will enable them as * required */ mc13783_write(MC13783_INTERRUPT_MASK0, 0xffffff); mc13783_write(MC13783_INTERRUPT_MASK1, 0xffffff); MC13783_GPIO_ISR = (1ul << MC13783_GPIO_LINE); mc13783_thread_id = create_thread(mc13783_interrupt_thread, mc13783_thread_stack, sizeof(mc13783_thread_stack), 0, mc13783_thread_name IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU)); }
uint32_t mc13783_clear(unsigned address, uint32_t bits) { uint32_t data; mutex_lock(&mc13783_spi_mutex); data = mc13783_read(address); if (data != MC13783_DATA_ERROR) mc13783_write(address, data & ~bits); mutex_unlock(&mc13783_spi_mutex); return data; }
bool _backlight_init(void) { /* Set default LED register value */ mc13783_write(MC13783_LED_CONTROL0, MC13783_LED_CONTROL0_BITS | MC13783_LEDEN); #ifdef HAVE_BACKLIGHT_BRIGHTNESS /* Our PWM and I-Level is different than retailos (but same apparent * brightness), so init to our default. */ _backlight_set_brightness(DEFAULT_BRIGHTNESS_SETTING); #else /* Use default PWM */ backlight_pwm_bits = mc13783_read(MC13783_LED_CONTROL2) & MC13783_LEDMDDC; #endif return true; }
void _backlight_off(void) { uint32_t ctrl0 = MC13783_LED_CONTROL0_BITS | MC13783_LEDEN; if (backlight_on_status) ctrl0 |= led_ramp_mask & MC13783_LEDMDRAMPDOWN; backlight_on_status = false; /* Set/clear LEDRAMPDOWN bit, clear LEDRAMPUP bit */ mc13783_write(MC13783_LED_CONTROL0, ctrl0); /* Wait 100us - 500ms */ sleep(HZ/100); /* Write final PWM setting */ mc13783_write_masked(MC13783_LED_CONTROL2, 0 << MC13783_LEDMDDC_POS, MC13783_LEDMDDC); }
uint32_t mc13783_write_masked(unsigned address, uint32_t data, uint32_t mask) { uint32_t old; mutex_lock(&mc13783_spi_mutex); old = mc13783_read(address); if (old != MC13783_DATA_ERROR) { data = (old & ~mask) | (data & mask); if (mc13783_write(address, data) != 1) old = MC13783_DATA_ERROR; } mutex_unlock(&mc13783_spi_mutex); return old; }