diff --git a/inc/frames.h b/inc/frames.h index 88e5b47beee409a23baa20d73c7ebdf13bd9b8e4..f5ffc92a049e1bf8c827d5c48e5f2258873c3ab3 100644 --- a/inc/frames.h +++ b/inc/frames.h @@ -1320,7 +1320,7 @@ const uint8_t flag19[1024] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; -const uint8_t dept[1024] = { +const uint8_t ece[1024] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/main.c b/src/main.c index cfcd5fc6180c344fd2843d276b93b68ee6abb748..62991d559557b02e02cfb315439b9281c440207a 100644 --- a/src/main.c +++ b/src/main.c @@ -24,7 +24,7 @@ volatile uint8_t lptim_ovf = 0; //0 if the lptimer has not overflowed (finished // ************** Prototypes ************** void system_reset(void); void APP_ErrorHandler(void); -void Put_Image(const uint8_t *bitmap); +void Put_Image(const uint8_t *bitmap, uint32_t delayTime); void Display_On(void); void ssd1306_clear(void); void Display_Init(void); @@ -52,9 +52,10 @@ void Accel_Init(void); void EXTI_Init(void); void Stop_Mode_EXTI_Init(void); void EXTI4_15_IRQHandler(void); -void Put_UNL_Info(void); +void Put_Default_Info(void); void Sleep(void); void ssd1306_rotate_180(void); +void Init(void); // ************** End Prototypes ************** void system_reset(void) { @@ -63,18 +64,17 @@ void system_reset(void) { while(1); } -void APP_ErrorHandler(void) -{ +void APP_ErrorHandler(void) { system_reset(); } -void I2C_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout){ - if (HAL_I2C_Master_Transmit(hi2c, DevAddress, pData, Size, Timeout) != HAL_OK){ +void I2C_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout) { + if (HAL_I2C_Master_Transmit(hi2c, DevAddress, pData, Size, Timeout) != HAL_OK) { APP_ErrorHandler(); } } -void Put_Image(const uint8_t *bitmap){ +void Put_Image(const uint8_t *bitmap, uint32_t delayTime) { // This if block is used to overide the bitmap displayed if the device is charging /* if (HAL_GPIO_ReadPin(GPIOF, GPIO_PIN_0) == GPIO_PIN_SET && HAL_GPIO_ReadPin(GPIOF, GPIO_PIN_1) == GPIO_PIN_SET){ @@ -101,9 +101,11 @@ void Put_Image(const uint8_t *bitmap){ I2C_Transmit(&hi2c1, SSD1306_ADDR, bitmap1, 6, 5000); I2C_Transmit(&hi2c1, SSD1306_ADDR, bitmap2, 2, 5000); I2C_Transmit(&hi2c1, SSD1306_ADDR, transmit, 1025, 5000); + + LPTIM_Delay(delayTime); // Show the image for a specifc amount of time on the keychain } -void Display_On(void){ +void Display_On(void) { I2C_Transmit(&hi2c1, SSD1306_ADDR, software_on, 2, 5000); } @@ -112,16 +114,13 @@ void ssd1306_clear(void) I2C_Transmit(&hi2c1, SSD1306_ADDR, bitmap1, 6, 5000); I2C_Transmit(&hi2c1, SSD1306_ADDR, bitmap2, 2, 5000); - for(int i =0; i < 32; i++) - { + for(int i =0; i < 32; i++) { I2C_Transmit(&hi2c1, SSD1306_ADDR, clear, 33, 5000); } } -void Display_Init(void) -{ - for(int i = 0; i < 12; i++) - { +void Display_Init(void) { + for(int i = 0; i < 12; i++) { I2C_Transmit(&hi2c1, SSD1306_ADDR, arr[i], init_len[i], 5000); } @@ -131,31 +130,24 @@ void Display_Init(void) Display_On(); } -void Put_GIF(const uint8_t ** image, int repeat, int frames, int reverse, int delayTime) -{ +void Put_GIF(const uint8_t ** image, int repeat, int frames, int reverse, int delayTime) { for(int i = 0; i < repeat; i++){ for(int j = 0; j < frames; j++){ - Put_Image(image[j]); - //HAL_Delay(delayTime); - LPTIM_Delay(delayTime); + Put_Image(image[j], delayTime); } if(reverse > 0){ for(int j = 0; j < frames; j++){ - Put_Image(image[frames-j]); - //HAL_Delay(delayTime); - LPTIM_Delay(delayTime); + Put_Image(image[frames-j], delayTime); } } } } -void SysTick_Handler(void) -{ +void SysTick_Handler(void) { HAL_IncTick(); } -static void APP_SystemClockConfig(void) // Setup HSI as 4MHz -{ +static void APP_SystemClockConfig(void) { // Setup HSI as 4MHz RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef LPTIM_RCC = {0}; @@ -173,8 +165,7 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz RCC_OscInitStruct.PLL.PLLState = RCC_PLL_OFF; /* Disable PLL */ /*RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;*/ /* Select HSI as PLL source */ /* Configure oscillators */ - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { APP_ErrorHandler(); } @@ -184,8 +175,7 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; /* AHB clock not divide */ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; /* APB clock not divided */ /* Configure clock source */ - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) - { + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { APP_ErrorHandler(); } @@ -193,8 +183,7 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz LPTIM_RCC.PeriphClockSelection = RCC_PERIPHCLK_LPTIM; /* Select peripheral clock: LPTIM */ LPTIM_RCC.LptimClockSelection = RCC_LPTIMCLKSOURCE_LSI; /* Select LPTIM clock source: LSI */ /* Peripheral clock initialization */ - if (HAL_RCCEx_PeriphCLKConfig(&LPTIM_RCC) != HAL_OK) - { + if (HAL_RCCEx_PeriphCLKConfig(&LPTIM_RCC) != HAL_OK) { APP_ErrorHandler(); } @@ -204,8 +193,7 @@ static void APP_SystemClockConfig(void) // Setup HSI as 4MHz __HAL_RCC_PWR_CLK_ENABLE(); // Enable the Power System Clock } -static void LPTIMInit(void) -{ +static void LPTIMInit(void) { /* LPTIM configuration */ LPTIMConf.Instance = LPTIM; /* LPTIM */ LPTIMConf.Init.Prescaler = LPTIM_PRESCALER_DIV128; /* Prescaler: 128 */ @@ -224,16 +212,15 @@ static void LPTIMInit(void) HAL_Delay(1); } -void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim){ +void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim) { lptim_ovf = 1; } - void LPTIM1_IRQHandler(void) -{ + void LPTIM1_IRQHandler(void) { HAL_LPTIM_IRQHandler(&LPTIMConf); } -void LPTIM_Delay(uint32_t millis){ +void LPTIM_Delay(uint32_t millis) { float counts = millis * 0.256f; // With the understanding the prescaler is 128 HAL_LPTIM_SetOnce_Start_IT(&LPTIMConf, (uint32_t)(counts + 0.5f)); HAL_SuspendTick(); @@ -249,7 +236,7 @@ void LPTIM_Delay(uint32_t millis){ HAL_Delay(1); // Shutdown time must be more than 120 microseconds } -void GPIO_Charger_EXTI_Init(void){ +void GPIO_Charger_EXTI_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; __HAL_RCC_GPIOF_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; @@ -264,12 +251,12 @@ void GPIO_Charger_EXTI_Init(void){ HAL_NVIC_EnableIRQ(EXTI0_1_IRQn); } -void EXTI0_1_IRQHandler(void){ +void EXTI0_1_IRQHandler(void) { HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); // Charging HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1); // Standby } -void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == GPIO_PIN_0){ // Charging Event charge = 1; standby = 0; @@ -300,7 +287,7 @@ void GPIO_I2C_Init(void) { //HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } -void display_Switch_Init(void){ +void display_Switch_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; @@ -310,12 +297,12 @@ void display_Switch_Init(void){ HAL_Delay(5); } -void display_Power_On(void){ +void display_Power_On(void) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET); LPTIM_Delay(100); } -void display_Power_Off(void){ +void display_Power_Off(void) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET); } @@ -345,8 +332,7 @@ uint8_t I2C_Scan(void) { } if (deviceFound == 1){ - Put_Image(dept); - LPTIM_Delay(3000); + Put_Image(ece, 3000); } if (deviceFound == 0) { @@ -356,17 +342,17 @@ uint8_t I2C_Scan(void) { return 1; } -void Accel_WriteReg(uint8_t reg, uint8_t value){ +void Accel_WriteReg(uint8_t reg, uint8_t value) { HAL_I2C_Mem_Write(&hi2c1, SC7A20_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &value, 1, HAL_MAX_DELAY); } -uint8_t Accel_ReadReg(uint8_t reg){ +uint8_t Accel_ReadReg(uint8_t reg) { uint8_t reg_value; HAL_I2C_Mem_Read(&hi2c1, SC7A20_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, ®_value, 1, HAL_MAX_DELAY); return reg_value; } -void LED_Init(void){ +void LED_Init(void) { __HAL_RCC_GPIOA_CLK_ENABLE(); // Enable GPIOA clock GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = GPIO_PIN_2; @@ -376,11 +362,11 @@ void LED_Init(void){ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } -void Toggle_LED(void){ +void Toggle_LED(void) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_2); } -void Accel_Init(void){ +void Accel_Init(void) { // Inits the accelerometer to send an interrupt signal on any axis movement. // First disable all output Accel_WriteReg(CTRL_REG1, 0x00); // Disable all axes and power down @@ -400,7 +386,7 @@ void Accel_Init(void){ EXTI_Init(); } -void EXTI_Init(void){ +void EXTI_Init(void) { GPIO_InitTypeDef GPIO_InitStruct={0}; __HAL_RCC_GPIOA_CLK_ENABLE(); // Enable GPIOA clock GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; // GPIO mode set to falling edge interrupt @@ -415,7 +401,7 @@ void EXTI_Init(void){ HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0); } -void Stop_Mode_EXTI_Init(void){ +void Stop_Mode_EXTI_Init(void) { __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStruct={0}; @@ -427,19 +413,18 @@ void Stop_Mode_EXTI_Init(void){ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } -// Handles the EXTI on PA5 -void EXTI4_15_IRQHandler(void) -{ +// Handles the EXTI of the Accelerometer on PA5 +void EXTI4_15_IRQHandler(void) { __NOP(); HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5); } -void ssd1306_rotate_180(void){ +void ssd1306_rotate_180(void) { uint8_t rotate[] = {0x00,0xA1,0xC8}; I2C_Transmit(&hi2c1, SSD1306_ADDR, rotate, 3, 5000); } -void Sleep(void){ +void Sleep(void) { I2C_Transmit(&hi2c1, SSD1306_ADDR, software_off, 2, 5000); display_Power_Off(); HAL_SuspendTick(); @@ -452,16 +437,14 @@ void Sleep(void){ Display_Init(); } -void Put_UNL_Info(void){ +void Put_Default_Info(void) { Put_GIF(herbie, 4, 18, 0, 63); - Put_Image(dept); - LPTIM_Delay(4000); + Put_Image(ece, 4000); Put_GIF(flag, 2, 20, 0, 10); Put_GIF(gbr, 2, 8, 1, 7); } -int main (void) -{ +void Init(void) { HAL_Init(); APP_SystemClockConfig(); LPTIMInit(); @@ -471,12 +454,19 @@ int main (void) I2C_Init(); Accel_Init(); Display_Init(); - +} + +int main (void) { + Init(); // Initializes all of the hardware. + while (1) { - Put_UNL_Info(); + Put_Default_Info(); // Places the default info on the display (what you see before any modifications). // Add more frames here + // Examples: + // Put_Image(ece, 4000); // This will put the ECE image on the keychain display for 4 seconds. + // Put_GIF(herbie, 4, 18, 0, 63); // This puts the herbie GIF on the display 4 times, back to back, with each frame lasting 63 miliseconds. - Sleep(); + Sleep(); // Put the keychain to sleep and clear the display. Will be woken up by detected motion. } }