kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Updated RV3028 driver to our coding style and included a standalone C example
rodzic
0549a57133
commit
80eddb24c7
|
@ -1,10 +1 @@
|
|||
add_library(rv3028 INTERFACE)
|
||||
|
||||
target_sources(rv3028 INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/rv3028.cpp
|
||||
)
|
||||
|
||||
target_include_directories(rv3028 INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(rv3028 INTERFACE pico_stdlib hardware_i2c)
|
||||
include(rv3028.cmake)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
add_library(rv3028 INTERFACE)
|
||||
set(DRIVER_NAME rv3028)
|
||||
add_library(${DRIVER_NAME} INTERFACE)
|
||||
|
||||
target_sources(rv3028 INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/rv3028.cpp
|
||||
)
|
||||
target_sources(${DRIVER_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${DRIVER_NAME}.cpp)
|
||||
|
||||
target_include_directories(rv3028 INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(rv3028 INTERFACE pico_stdlib hardware_i2c)
|
||||
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_i2c)
|
||||
|
|
Plik diff jest za duży
Load Diff
|
@ -179,127 +179,152 @@ Distributed as-is; no warranty is given.
|
|||
namespace pimoroni {
|
||||
|
||||
enum time_order {
|
||||
TIME_SECONDS, // 0
|
||||
TIME_MINUTES, // 1
|
||||
TIME_HOURS, // 2
|
||||
TIME_WEEKDAY, // 3
|
||||
TIME_DATE, // 4
|
||||
TIME_MONTH, // 5
|
||||
TIME_YEAR, // 6
|
||||
TIME_SECONDS, // 0
|
||||
TIME_MINUTES, // 1
|
||||
TIME_HOURS, // 2
|
||||
TIME_WEEKDAY, // 3
|
||||
TIME_DATE, // 4
|
||||
TIME_MONTH, // 5
|
||||
TIME_YEAR, // 6
|
||||
};
|
||||
|
||||
class RV3028
|
||||
{
|
||||
i2c_inst_t *i2c = i2c0;
|
||||
// interface pins with our standard defaults where appropriate
|
||||
int8_t sda = 20;
|
||||
int8_t scl = 21;
|
||||
int8_t interrupt = 22;
|
||||
public:
|
||||
RV3028() {}
|
||||
|
||||
RV3028(i2c_inst_t *i2c, uint8_t sda, uint8_t scl, uint8_t interrupt) :
|
||||
i2c(i2c), sda(sda), scl(scl), interrupt(interrupt) {}
|
||||
|
||||
void init();
|
||||
|
||||
bool setup(bool set_24Hour = true, bool disable_TrickleCharge = true, bool set_LevelSwitchingMode = true);
|
||||
bool setTime(uint8_t sec, uint8_t min, uint8_t hour, uint8_t weekday, uint8_t date, uint8_t month, uint16_t year);
|
||||
bool setTime(uint8_t * time, uint8_t len);
|
||||
bool setSeconds(uint8_t value);
|
||||
bool setMinutes(uint8_t value);
|
||||
bool setHours(uint8_t value);
|
||||
bool setWeekday(uint8_t value);
|
||||
bool setDate(uint8_t value);
|
||||
bool setMonth(uint8_t value);
|
||||
bool setYear(uint16_t value);
|
||||
bool setToCompilerTime(); //Uses the hours, mins, etc from compile time to set RTC
|
||||
|
||||
bool updateTime() ; //Update the local array with the RTC registers
|
||||
|
||||
char* stringDateUSA(); //Return date in mm-dd-yyyy
|
||||
char* stringDate(); //Return date in dd-mm-yyyy
|
||||
char* stringTime(); //Return time hh:mm:ss with AM/PM if in 12 hour mode
|
||||
char* stringTimeStamp(); //Return timeStamp in ISO 8601 format yyyy-mm-ddThh:mm:ss
|
||||
|
||||
uint8_t getSeconds();
|
||||
uint8_t getMinutes();
|
||||
uint8_t getHours();
|
||||
uint8_t getWeekday();
|
||||
uint8_t getDate();
|
||||
uint8_t getMonth();
|
||||
uint16_t getYear();
|
||||
class RV3028 {
|
||||
//--------------------------------------------------
|
||||
// Constants
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
static const uint8_t DEFAULT_I2C_ADDRESS = RV3028_ADDR;
|
||||
static const uint8_t DEFAULT_SDA_PIN = 20;
|
||||
static const uint8_t DEFAULT_SCL_PIN = 21;
|
||||
static const uint8_t DEFAULT_INT_PIN = 22;
|
||||
static const uint8_t PIN_UNUSED = UINT8_MAX;
|
||||
|
||||
|
||||
bool is12Hour(); //Returns true if 12hour bit is set
|
||||
bool isPM(); //Returns true if is12Hour and PM bit is set
|
||||
void set12Hour();
|
||||
void set24Hour();
|
||||
|
||||
bool setUNIX(uint32_t value);//Set the UNIX Time (Real Time and UNIX Time are INDEPENDENT!)
|
||||
uint32_t getUNIX();
|
||||
|
||||
void enableAlarmInterrupt(uint8_t min, uint8_t hour, uint8_t date_or_weekday, bool setWeekdayAlarm_not_Date, uint8_t mode, bool enable_clock_output = false);
|
||||
void enableAlarmInterrupt();
|
||||
void disableAlarmInterrupt();
|
||||
bool readAlarmInterruptFlag();
|
||||
void clearAlarmInterruptFlag();
|
||||
|
||||
void setTimer(bool timer_repeat, uint16_t timer_frequency, uint16_t timer_value, bool setInterrupt, bool start_timer, bool enable_clock_output = false);
|
||||
uint16_t getTimerCount(void);
|
||||
void enableTimer();
|
||||
void disableTimer();
|
||||
void enableTimerInterrupt();
|
||||
void disableTimerInterrupt();
|
||||
bool readTimerInterruptFlag();
|
||||
void clearTimerInterruptFlag();
|
||||
|
||||
void enablePeriodicUpdateInterrupt(bool every_second, bool enable_clock_output = false);
|
||||
void disablePeriodicUpdateInterrupt();
|
||||
bool readPeriodicUpdateInterruptFlag();
|
||||
void clearPeriodicUpdateInterruptFlag();
|
||||
|
||||
void enableTrickleCharge(uint8_t tcr = TCR_15K); //Trickle Charge Resistor default 15k
|
||||
void disableTrickleCharge();
|
||||
bool setBackupSwitchoverMode(uint8_t val);
|
||||
|
||||
void enableClockOut(uint8_t freq);
|
||||
void enableInterruptControlledClockout(uint8_t freq);
|
||||
void disableClockOut();
|
||||
bool readClockOutputInterruptFlag();
|
||||
void clearClockOutputInterruptFlag();
|
||||
|
||||
uint8_t status(); //Returns the status byte
|
||||
void clearInterrupts();
|
||||
|
||||
//Values in RTC are stored in Binary Coded Decimal. These functions convert to/from Decimal
|
||||
uint8_t BCDtoDEC(uint8_t val);
|
||||
uint8_t DECtoBCD(uint8_t val);
|
||||
|
||||
uint8_t readRegister(uint8_t addr);
|
||||
bool writeRegister(uint8_t addr, uint8_t val);
|
||||
bool readMultipleRegisters(uint8_t addr, uint8_t * dest, uint8_t len);
|
||||
bool writeMultipleRegisters(uint8_t addr, uint8_t * values, uint8_t len);
|
||||
|
||||
bool writeConfigEEPROM_RAMmirror(uint8_t eepromaddr, uint8_t val);
|
||||
uint8_t readConfigEEPROM_RAMmirror(uint8_t eepromaddr);
|
||||
bool waitforEEPROM();
|
||||
void reset();
|
||||
|
||||
void setBit(uint8_t reg_addr, uint8_t bit_num);
|
||||
void clearBit(uint8_t reg_addr, uint8_t bit_num);
|
||||
bool readBit(uint8_t reg_addr, uint8_t bit_num);
|
||||
//--------------------------------------------------
|
||||
// Variables
|
||||
//--------------------------------------------------
|
||||
private:
|
||||
uint8_t _time[TIME_ARRAY_LENGTH];
|
||||
i2c_inst_t *_i2cPort;
|
||||
int8_t address = RV3028_ADDR;
|
||||
i2c_inst_t *i2c = i2c0;
|
||||
|
||||
// From i2cdevice
|
||||
int write_bytes(uint8_t reg, uint8_t *buf, int len);
|
||||
int read_bytes(uint8_t reg, uint8_t *buf, int len);
|
||||
uint8_t get_bits(uint8_t reg, uint8_t shift, uint8_t mask=0b1);
|
||||
void set_bits(uint8_t reg, uint8_t shift, uint8_t mask=0b1);
|
||||
void clear_bits(uint8_t reg, uint8_t shift, uint8_t mask=0b1);
|
||||
// interface pins with our standard defaults where appropriate
|
||||
int8_t address = DEFAULT_I2C_ADDRESS;
|
||||
int8_t sda = DEFAULT_SDA_PIN;
|
||||
int8_t scl = DEFAULT_SCL_PIN;
|
||||
int8_t interrupt = DEFAULT_INT_PIN;
|
||||
|
||||
uint8_t times[TIME_ARRAY_LENGTH];
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Constructors/Destructor
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
RV3028() {}
|
||||
|
||||
RV3028(i2c_inst_t *i2c, uint8_t sda, uint8_t scl, uint8_t interrupt = PIN_UNUSED) :
|
||||
i2c(i2c), sda(sda), scl(scl), interrupt(interrupt) {}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Methods
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
bool init();
|
||||
|
||||
bool setup(bool set_24Hour = true, bool disable_TrickleCharge = true, bool set_LevelSwitchingMode = true);
|
||||
bool set_time(uint8_t sec, uint8_t min, uint8_t hour, uint8_t weekday, uint8_t date, uint8_t month, uint16_t year);
|
||||
bool set_time(uint8_t *time, uint8_t len);
|
||||
bool set_seconds(uint8_t value);
|
||||
bool set_minutes(uint8_t value);
|
||||
bool set_hours(uint8_t value);
|
||||
bool set_weekday(uint8_t value);
|
||||
bool set_date(uint8_t value);
|
||||
bool set_month(uint8_t value);
|
||||
bool set_year(uint16_t value);
|
||||
bool set_to_compiler_time(); //Uses the hours, mins, etc from compile time to set RTC
|
||||
|
||||
bool update_time(); //Update the local array with the RTC registers
|
||||
|
||||
char* string_date_usa(); //Return date in mm-dd-yyyy
|
||||
char* string_date(); //Return date in dd-mm-yyyy
|
||||
char* string_time(); //Return time hh:mm:ss with AM/PM if in 12 hour mode
|
||||
char* string_time_stamp(); //Return timeStamp in ISO 8601 format yyyy-mm-ddThh:mm:ss
|
||||
|
||||
uint8_t get_seconds();
|
||||
uint8_t get_minutes();
|
||||
uint8_t get_hours();
|
||||
uint8_t get_weekday();
|
||||
uint8_t get_date();
|
||||
uint8_t get_month();
|
||||
uint16_t get_year();
|
||||
|
||||
|
||||
bool is_12_hour(); //Returns true if 12hour bit is set
|
||||
bool is_pm(); //Returns true if is12Hour and PM bit is set
|
||||
void set_12_hour();
|
||||
void set_24_hour();
|
||||
|
||||
bool set_unix(uint32_t value); //Set the UNIX Time (Real Time and UNIX Time are INDEPENDENT!)
|
||||
uint32_t get_unix();
|
||||
|
||||
void enable_alarm_interrupt(uint8_t min, uint8_t hour, uint8_t date_or_weekday, bool setWeekdayAlarm_not_Date, uint8_t mode, bool enable_clock_output = false);
|
||||
void enable_alarm_interrupt();
|
||||
void disable_alarm_interrupt();
|
||||
bool read_alarm_interrupt_flag();
|
||||
void clear_alarm_interrupt_flag();
|
||||
|
||||
void set_timer(bool timer_repeat, uint16_t timer_frequency, uint16_t timer_value, bool setInterrupt, bool start_timer, bool enable_clock_output = false);
|
||||
uint16_t get_timer_count(void);
|
||||
void enable_timer();
|
||||
void disable_timer();
|
||||
void enable_timer_interrupt();
|
||||
void disable_timer_interrupt();
|
||||
bool read_timer_interrupt_flag();
|
||||
void clear_timer_interrupt_flag();
|
||||
|
||||
void enable_periodic_update_interrupt(bool every_second, bool enable_clock_output = false);
|
||||
void disable_periodic_update_interrupt();
|
||||
bool read_periodic_update_interrupt_flag();
|
||||
void clear_periodic_update_interrupt_flag();
|
||||
|
||||
void enable_trickle_charge(uint8_t tcr = TCR_15K); //Trickle Charge Resistor default 15k
|
||||
void disable_trickle_charge();
|
||||
bool set_backup_switchover_mode(uint8_t val);
|
||||
|
||||
void enable_clock_out(uint8_t freq);
|
||||
void enable_interrupt_controlled_clockout(uint8_t freq);
|
||||
void disable_clock_out();
|
||||
bool read_clock_output_interrupt_flag();
|
||||
void clear_clock_output_interrupt_flag();
|
||||
|
||||
uint8_t status(); //Returns the status byte
|
||||
void clear_interrupts();
|
||||
|
||||
//Values in RTC are stored in Binary Coded Decimal. These functions convert to/from Decimal
|
||||
uint8_t bcd_to_dec(uint8_t val);
|
||||
uint8_t dec_to_bcd(uint8_t val);
|
||||
|
||||
uint8_t read_register(uint8_t addr);
|
||||
bool write_register(uint8_t addr, uint8_t val);
|
||||
bool read_multiple_registers(uint8_t addr, uint8_t *dest, uint8_t len);
|
||||
bool write_multiple_registers(uint8_t addr, uint8_t *values, uint8_t len);
|
||||
|
||||
bool write_config_eeprom_ram_mirror(uint8_t eepromaddr, uint8_t val);
|
||||
uint8_t read_config_eeprom_ram_mirror(uint8_t eepromaddr);
|
||||
bool wait_for_eeprom();
|
||||
void reset();
|
||||
|
||||
void set_bit(uint8_t reg_addr, uint8_t bit_num);
|
||||
void clear_bit(uint8_t reg_addr, uint8_t bit_num);
|
||||
bool read_bit(uint8_t reg_addr, uint8_t bit_num);
|
||||
|
||||
private:
|
||||
// From i2cdevice
|
||||
int write_bytes(uint8_t reg, uint8_t *buf, int len);
|
||||
int read_bytes(uint8_t reg, uint8_t *buf, int len);
|
||||
uint8_t get_bits(uint8_t reg, uint8_t shift, uint8_t mask = 0b1);
|
||||
void set_bits(uint8_t reg, uint8_t shift, uint8_t mask = 0b1);
|
||||
void clear_bits(uint8_t reg, uint8_t shift, uint8_t mask = 0b1);
|
||||
};
|
||||
|
||||
//POSSIBLE ENHANCEMENTS :
|
||||
|
|
|
@ -8,6 +8,7 @@ add_subdirectory(breakout_rgbmatrix5x5)
|
|||
add_subdirectory(breakout_matrix11x7)
|
||||
add_subdirectory(breakout_mics6814)
|
||||
add_subdirectory(breakout_potentiometer)
|
||||
add_subdirectory(breakout_rtc)
|
||||
add_subdirectory(breakout_trackball)
|
||||
add_subdirectory(breakout_sgp30)
|
||||
add_subdirectory(breakout_colourlcd240x240)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
set(OUTPUT_NAME rtc_demo)
|
||||
|
||||
add_executable(
|
||||
${OUTPUT_NAME}
|
||||
demo.cpp
|
||||
)
|
||||
|
||||
# enable usb output, disable uart output
|
||||
pico_enable_stdio_usb(${OUTPUT_NAME} 1)
|
||||
pico_enable_stdio_uart(${OUTPUT_NAME} 0)
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_rtc)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(${OUTPUT_NAME})
|
|
@ -0,0 +1,45 @@
|
|||
#include "pico/stdlib.h"
|
||||
|
||||
#include "breakout_rtc.hpp"
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
BreakoutRTC rtc;
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
|
||||
rtc.init();
|
||||
// rtc.setup(false);
|
||||
|
||||
// Uncomment the below line on first run to set the RTC date and time to the program's compiler time
|
||||
// rtc.set_to_compiler_time();
|
||||
|
||||
// Make sure we have 24-hour time
|
||||
if(rtc.is_12_hour())
|
||||
rtc.set_24_hour();
|
||||
|
||||
// Set to update once per second
|
||||
rtc.enable_periodic_update_interrupt(true);
|
||||
|
||||
while(true) {
|
||||
//Has a second passed?
|
||||
if(rtc.read_periodic_update_interrupt_flag()) {
|
||||
rtc.clear_periodic_update_interrupt_flag();
|
||||
|
||||
//Update the locally stored time from the RTC
|
||||
if(rtc.update_time()) {
|
||||
printf("Date: %s, Time: %s\n", rtc.string_date(), rtc.string_time());
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, true);
|
||||
sleep_ms(100);
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, false);
|
||||
}
|
||||
}
|
||||
sleep_ms(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
set(OUTPUT_NAME rtc_display)
|
||||
|
||||
add_executable(
|
||||
rtc_display
|
||||
${OUTPUT_NAME}
|
||||
demo.cpp
|
||||
)
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(rtc_display pico_stdlib pico_explorer pico_display rv3028)
|
||||
target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_rtc)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(rtc_display)
|
||||
pico_add_extra_outputs(${OUTPUT_NAME})
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#else
|
||||
#include "pico_display.hpp"
|
||||
#endif
|
||||
#include "rv3028.hpp"
|
||||
#include "breakout_rtc.hpp"
|
||||
|
||||
#define MODE_DISP_CLOCK 0
|
||||
#define MODE_DISP_TIMER 1
|
||||
|
@ -47,15 +47,17 @@ uint16_t screen_width = PicoDisplay::WIDTH;
|
|||
uint16_t screen_height = PicoDisplay::HEIGHT;
|
||||
#endif
|
||||
|
||||
RV3028 rv3028;
|
||||
BreakoutRTC rtc;
|
||||
|
||||
#define LOW_COUNT_MOD 40
|
||||
#define HIGH_COUNT_MOD 20
|
||||
|
||||
bool repeat_count_reached(uint16_t curr_count) {
|
||||
// Check whether the current counter means that a key has repeated
|
||||
if (curr_count <= 10*LOW_COUNT_MOD) {
|
||||
if(curr_count <= 10*LOW_COUNT_MOD) {
|
||||
return (0 == (curr_count % LOW_COUNT_MOD));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return (0 == (curr_count % HIGH_COUNT_MOD));
|
||||
}
|
||||
}
|
||||
|
@ -65,10 +67,11 @@ void flash_led(uint32_t curr_count) {
|
|||
// Flash the LED based on the current loop counter
|
||||
// curr_count=0 will turn LED off
|
||||
#ifndef USE_PICO_EXPLORER
|
||||
if ((curr_count % FLASH_MOD) < (FLASH_MOD / 2)) {
|
||||
if((curr_count % FLASH_MOD) < (FLASH_MOD / 2)) {
|
||||
// value less than half modded number - LED off
|
||||
pico_display.set_led(0, 0, 0);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// value more than half modded number - LED on
|
||||
pico_display.set_led(128, 128, 128);
|
||||
}
|
||||
|
@ -78,11 +81,12 @@ void flash_led(uint32_t curr_count) {
|
|||
int main() {
|
||||
pico_display.init();
|
||||
|
||||
rv3028.init();
|
||||
// rv3028.setup(false);
|
||||
rtc.init();
|
||||
// rtc.setup(false);
|
||||
|
||||
// Make sure we have 24-hour time (smaller dsplay!)
|
||||
if (rv3028.is12Hour()) rv3028.set24Hour();
|
||||
// Make sure we have 24-hour time (smaller display!)
|
||||
if(rtc.is_12_hour())
|
||||
rtc.set_24_hour();
|
||||
|
||||
// Use these variables to make the buttons single-shot
|
||||
// Counts number of loops pressed, 0 if not pressed
|
||||
|
@ -108,71 +112,80 @@ int main() {
|
|||
|
||||
while(true) {
|
||||
|
||||
if (a_pressed == 0 && pico_display.is_pressed(pico_display.A)) {
|
||||
if(a_pressed == 0 && pico_display.is_pressed(pico_display.A)) {
|
||||
a_pressed = 1;
|
||||
if (display_mode == MODE_DISP_CLOCK) {
|
||||
if(display_mode == MODE_DISP_CLOCK) {
|
||||
// We were displaying clock = set up timer
|
||||
display_mode = MODE_SET_TIMER;
|
||||
} else if (display_mode == MODE_SET_TIMER) {
|
||||
}
|
||||
else if(display_mode == MODE_SET_TIMER) {
|
||||
// We were setting up the timer - run it
|
||||
rv3028.setTimer(false, 1, timer_count, true, true, false);
|
||||
rtc.set_timer(false, 1, timer_count, true, true, false);
|
||||
display_mode = MODE_DISP_TIMER;
|
||||
} else if (display_mode == MODE_DISP_TIMER) {
|
||||
}
|
||||
else if(display_mode == MODE_DISP_TIMER) {
|
||||
// We were running the timer - go back to setting up
|
||||
if (0 == (timer_count = rv3028.getTimerCount())) {
|
||||
if(0 == (timer_count = rtc.get_timer_count())) {
|
||||
timer_count = DEFAULT_TIMER_COUNT;
|
||||
}
|
||||
rv3028.disableTimerInterrupt();
|
||||
rv3028.disableTimer();
|
||||
rv3028.clearTimerInterruptFlag();
|
||||
rtc.disable_timer_interrupt();
|
||||
rtc.disable_timer();
|
||||
rtc.clear_timer_interrupt_flag();
|
||||
display_mode = MODE_SET_TIMER;
|
||||
}
|
||||
} else if (a_pressed >= 1 && !pico_display.is_pressed(pico_display.A)) {
|
||||
}
|
||||
else if(a_pressed >= 1 && !pico_display.is_pressed(pico_display.A)) {
|
||||
a_pressed = 0;
|
||||
}
|
||||
|
||||
if (b_pressed == 0 && pico_display.is_pressed(pico_display.B)) {
|
||||
if(b_pressed == 0 && pico_display.is_pressed(pico_display.B)) {
|
||||
b_pressed = 1;
|
||||
if ((display_mode == MODE_DISP_TIMER)
|
||||
if((display_mode == MODE_DISP_TIMER)
|
||||
|| (display_mode == MODE_SET_TIMER)) {
|
||||
// We were setting or displaying timer - revert to clock
|
||||
rv3028.disableTimerInterrupt();
|
||||
rv3028.disableTimer();
|
||||
rv3028.clearTimerInterruptFlag();
|
||||
rtc.disable_timer_interrupt();
|
||||
rtc.disable_timer();
|
||||
rtc.clear_timer_interrupt_flag();
|
||||
display_mode = MODE_DISP_CLOCK;
|
||||
timer_count = DEFAULT_TIMER_COUNT;
|
||||
}
|
||||
} else if (b_pressed >= 1 && !pico_display.is_pressed(pico_display.B)) {
|
||||
}
|
||||
else if(b_pressed >= 1 && !pico_display.is_pressed(pico_display.B)) {
|
||||
b_pressed = 0;
|
||||
}
|
||||
|
||||
if (x_pressed == 0 && pico_display.is_pressed(pico_display.X)) {
|
||||
if(x_pressed == 0 && pico_display.is_pressed(pico_display.X)) {
|
||||
x_pressed = 1;
|
||||
if (display_mode == MODE_SET_TIMER) {
|
||||
if(display_mode == MODE_SET_TIMER) {
|
||||
// Setting timer - Increment count
|
||||
timer_count++;
|
||||
}
|
||||
} else if (x_pressed >= 1 && pico_display.is_pressed(pico_display.X)) {
|
||||
}
|
||||
else if(x_pressed >= 1 && pico_display.is_pressed(pico_display.X)) {
|
||||
// Button still pressed - check if has reached repeat count
|
||||
if (repeat_count_reached(x_pressed++)) {
|
||||
if(repeat_count_reached(x_pressed++)) {
|
||||
timer_count++;
|
||||
}
|
||||
} else if (x_pressed >= 1 && !pico_display.is_pressed(pico_display.X)) {
|
||||
}
|
||||
else if(x_pressed >= 1 && !pico_display.is_pressed(pico_display.X)) {
|
||||
x_pressed = 0;
|
||||
}
|
||||
|
||||
if (y_pressed == 0 && pico_display.is_pressed(pico_display.Y)) {
|
||||
if(y_pressed == 0 && pico_display.is_pressed(pico_display.Y)) {
|
||||
y_pressed = 1;
|
||||
if (display_mode == MODE_SET_TIMER) {
|
||||
if(display_mode == MODE_SET_TIMER) {
|
||||
// Setting timer - Decrement count
|
||||
if (timer_count >= 1) timer_count--;
|
||||
}
|
||||
} else if (y_pressed >= 1 && pico_display.is_pressed(pico_display.Y)) {
|
||||
}
|
||||
else if(y_pressed >= 1 && pico_display.is_pressed(pico_display.Y)) {
|
||||
// Button still pressed - check if has reached repeat count
|
||||
if (repeat_count_reached(y_pressed++)) {
|
||||
if (timer_count >= 1) timer_count--;
|
||||
if(repeat_count_reached(y_pressed++)) {
|
||||
if(timer_count >= 1)
|
||||
timer_count--;
|
||||
}
|
||||
} else if (y_pressed >= 1 && !pico_display.is_pressed(pico_display.Y)) {
|
||||
}
|
||||
else if(y_pressed >= 1 && !pico_display.is_pressed(pico_display.Y)) {
|
||||
y_pressed = 0;
|
||||
}
|
||||
|
||||
|
@ -182,32 +195,34 @@ int main() {
|
|||
// text_box.deflate(10);
|
||||
pico_display.set_clip(text_box);
|
||||
pico_display.set_pen(255, 255, 255);
|
||||
switch (display_mode) {
|
||||
switch(display_mode) {
|
||||
case MODE_DISP_CLOCK:
|
||||
// Show the clock face
|
||||
flash_led(0);
|
||||
if (rv3028.updateTime()) {
|
||||
if(rtc.update_time()) {
|
||||
pico_display.text("Set Timer",
|
||||
Point(text_box.x, text_box.y+2), 230, 1);
|
||||
pico_display.set_pen(0, 255, 0);
|
||||
pico_display.text(rv3028.stringDate(),
|
||||
pico_display.text(rtc.string_date(),
|
||||
Point(text_box.x, text_box.y+20), 230, 4);
|
||||
pico_display.set_pen(255, 0, 0);
|
||||
pico_display.text(rv3028.stringTime(),
|
||||
pico_display.text(rtc.string_time(),
|
||||
Point(text_box.x, text_box.y+60), 230, 6);
|
||||
pico_display.set_pen(255, 255, 255);
|
||||
pico_display.text("Clock",
|
||||
Point(text_box.x, text_box.y+screen_height-20), 230, 1);
|
||||
} else {
|
||||
sprintf(buf, "Time: rv3028.updateTime() ret err");
|
||||
}
|
||||
else {
|
||||
sprintf(buf, "Time: rtc.updateTime() ret err");
|
||||
pico_display.text(buf,
|
||||
Point(text_box.x, text_box.y), 30, 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_DISP_TIMER:
|
||||
pico_display.text("Set Timer",
|
||||
Point(text_box.x, text_box.y+2), 230, 1);
|
||||
if (rv3028.readTimerInterruptFlag()) {
|
||||
if(rtc.read_timer_interrupt_flag()) {
|
||||
// Go periodic time interupt - say loop ended
|
||||
pico_display.set_pen(255, 0, 0);
|
||||
sprintf(buf, "%s", "Timer complete");
|
||||
|
@ -215,14 +230,16 @@ int main() {
|
|||
Point(text_box.x, text_box.y+30), 230, 4);
|
||||
pico_display.set_pen(255, 255, 255);
|
||||
flash_led(i);
|
||||
} else {
|
||||
sprintf(buf, "%s %d", "Timer running", rv3028.getTimerCount());
|
||||
}
|
||||
else {
|
||||
sprintf(buf, "%s %d", "Timer running", rtc.get_timer_count());
|
||||
pico_display.text(buf,
|
||||
Point(text_box.x, text_box.y+30), 230, 3);
|
||||
}
|
||||
pico_display.text("Clock",
|
||||
Point(text_box.x, text_box.y+screen_height-20), 230, 1);
|
||||
break;
|
||||
|
||||
case MODE_SET_TIMER:
|
||||
flash_led(0);
|
||||
pico_display.text("Run Timer",
|
||||
|
@ -248,5 +265,5 @@ int main() {
|
|||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ add_subdirectory(breakout_rgbmatrix5x5)
|
|||
add_subdirectory(breakout_matrix11x7)
|
||||
add_subdirectory(breakout_mics6814)
|
||||
add_subdirectory(breakout_potentiometer)
|
||||
add_subdirectory(breakout_rtc)
|
||||
add_subdirectory(breakout_trackball)
|
||||
add_subdirectory(breakout_sgp30)
|
||||
add_subdirectory(breakout_as7262)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
include(breakout_rtc.cmake)
|
|
@ -0,0 +1,11 @@
|
|||
set(LIB_NAME breakout_rtc)
|
||||
add_library(${LIB_NAME} INTERFACE)
|
||||
|
||||
target_sources(${LIB_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib rv3028)
|
|
@ -0,0 +1,5 @@
|
|||
#include "breakout_rtc.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../drivers/rv3028/rv3028.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
typedef RV3028 BreakoutRTC;
|
||||
}
|
Ładowanie…
Reference in New Issue