123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #include "mbed.h"
- #include "main.h"
- #include "SWO.h"
- #include "pca9685.h"
- #include "tusb322.h"
- #include "ds3231.h"
- #include "ioc.h"
- #include "animation.h"
- I2C i2c(PA_10, PA_9);
- // SWO_Channel swo("swo");
- bool LED;
- void RtcCallback(void) {
- LED = !LED;
- LED_SetOutput(LED);
- }
- int main() {
-
- // Start I2C at 400kHz for DS3231
- i2c.frequency(400000);
-
- // Start with HV PSU disabled
- HV_EnableOutput(false);
-
- TUSB322_Init();
- PCA9685_Init();
- DS3231_Init(RtcCallback);
-
- // Enable HV PSU
- HV_EnableOutput(true);
-
- // Set PCA9685 input voltage to highest possible
- PCA9685_SetVoltage(1.0);
-
- // swo.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
-
- // Bump I2C frequency to 1MHz for PCA9685
- // i2c.frequency(1000000);
- // DS3231_SetTime(0, 55, 6, true);
- // DS3231_SetDate(0, 2, 12, 18, 0);
- int currMinute = 0, currHour = 0;
- int nextSecond, nextMinute, nextHour;
- while(1) {
-
- DS3231_GetTime(&nextSecond, &nextMinute, &nextHour);
- if (nextMinute != currMinute) {
- PCA9685_SetDigit(3, currMinute % 10, PCA9685_Min_Brightness);
- PCA9685_SetDigit(2, currMinute / 10, PCA9685_Min_Brightness);
- PCA9685_SetDigit(3, nextMinute % 10, PCA9685_Max_Brightness);
- PCA9685_SetDigit(2, nextMinute / 10, PCA9685_Max_Brightness);
- currMinute = nextMinute;
- }
- if (nextHour != currHour) {
- PCA9685_SetDigit(1, currHour % 10, PCA9685_Min_Brightness);
- PCA9685_SetDigit(0, currHour / 10, PCA9685_Min_Brightness);
- PCA9685_SetDigit(1, nextHour % 10, PCA9685_Max_Brightness);
- PCA9685_SetDigit(0, nextHour / 10, PCA9685_Max_Brightness);
- currHour = nextHour;
- }
- wait(0.1);
- // Animate_Cycle_Basic();
- // Animate_Cycle_Analog();
- // Animate_Cycle_Low_Pwm();
- // Animate_Cycle_Pwm();
- // Animate_Cycle_Fade();
- // Animate_Cycle_Fade_Random();
- // Animate_Cycle_Fast();
- // Animate_Cycle_Fast_Random();
- }
- }
- void I2C_Write(int DeviceAddress, char RegAddress, char *Data, int Length) {
- char buffer[I2C_MAX_BUFFER+1] = {0};
- if (Length > I2C_MAX_BUFFER) LED_Fault(1);
- buffer[0] = RegAddress;
- memcpy(&buffer[1], Data, Length);
- i2c.write(DeviceAddress << 1, buffer, Length + 1);
- }
- void I2C_Read(int DeviceAddress, char RegAddress, char *Data, int Length) {
-
- i2c.write(DeviceAddress << 1, &RegAddress, 1);
- i2c.read(DeviceAddress << 1, Data, Length);
- }
|