From 66bc316c6be019b3ca938280a803b918097a4431 Mon Sep 17 00:00:00 2001 From: wangyz1997 Date: Fri, 6 Dec 2024 15:52:54 +0800 Subject: [PATCH] stm32f0_clock: convert tabs to spaces --- stm32f0_clock/Bsp/Src/bsp_buzzer.c | 6 ++--- stm32f0_clock/Bsp/Src/bsp_ds18b20.c | 22 +++++++++---------- stm32f0_clock/Bsp/Src/bsp_ds3231.c | 34 ++++++++++++++--------------- stm32f0_clock/Bsp/Src/bsp_key.c | 8 +++---- stm32f0_clock/Core/Src/app_main.c | 4 ++-- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/stm32f0_clock/Bsp/Src/bsp_buzzer.c b/stm32f0_clock/Bsp/Src/bsp_buzzer.c index b9ae261..e9bba33 100644 --- a/stm32f0_clock/Bsp/Src/bsp_buzzer.c +++ b/stm32f0_clock/Bsp/Src/bsp_buzzer.c @@ -42,10 +42,10 @@ void bsp_buzzer_play_note(bsp_buzzer_key key) } else { uint32_t psc = SystemCoreClock / note_frequency_table[key]; uint32_t oc = psc * bsp_buzzer_volume_percent / 100; - + __HAL_TIM_SET_AUTORELOAD(&BSP_BUZZER_PWM_TIM, psc); //32位定时器 __HAL_TIM_SET_COMPARE(&BSP_BUZZER_PWM_TIM, BSP_BUZZER_PWM_CH, oc); - + HAL_TIM_PWM_Start(&BSP_BUZZER_PWM_TIM, BSP_BUZZER_PWM_CH); } } @@ -56,7 +56,7 @@ void bsp_buzzer_play_song(const uint8_t *note_table, uint32_t note_count) bsp_buzzer_play_note(note_table[i * 2]); HAL_Delay(note_table[i * 2 + 1] * 8); } - + bsp_buzzer_play_note(STOP); } diff --git a/stm32f0_clock/Bsp/Src/bsp_ds18b20.c b/stm32f0_clock/Bsp/Src/bsp_ds18b20.c index 822db8e..3bb2289 100644 --- a/stm32f0_clock/Bsp/Src/bsp_ds18b20.c +++ b/stm32f0_clock/Bsp/Src/bsp_ds18b20.c @@ -12,7 +12,7 @@ static void bsp_ds18b20_delay_us(uint16_t delay_us) //实际延时时间会比de static void bsp_ds18b20_reset_bus(void) { HAL_GPIO_WritePin(ONEWIRE_GPIO_Port, ONEWIRE_Pin, GPIO_PIN_RESET); //拉低DQ - bsp_ds18b20_delay_us(500); //拉低500us 复位总线 + bsp_ds18b20_delay_us(500); //拉低500us 复位总线 HAL_GPIO_WritePin(ONEWIRE_GPIO_Port, ONEWIRE_Pin, GPIO_PIN_SET); } @@ -40,7 +40,7 @@ static uint8_t bsp_ds18b20_read_byte(void) for(uint8_t i = 0; i < 8; i ++) { byte >>= 1; - + HAL_GPIO_WritePin(ONEWIRE_GPIO_Port, ONEWIRE_Pin, GPIO_PIN_RESET); bsp_ds18b20_delay_us(2); //拉低2us 开始读取 HAL_GPIO_WritePin(ONEWIRE_GPIO_Port, ONEWIRE_Pin, GPIO_PIN_SET); @@ -49,7 +49,7 @@ static uint8_t bsp_ds18b20_read_byte(void) if(HAL_GPIO_ReadPin(ONEWIRE_GPIO_Port, ONEWIRE_Pin) == GPIO_PIN_SET) { byte |= 0x80; //最高位为1 } - + bsp_ds18b20_delay_us(45); bsp_ds18b20_delay_us(1); //1us recover time } @@ -93,25 +93,25 @@ HAL_StatusTypeDef bsp_ds18b20_start_conv(void) //开始温度转换 HAL_StatusTypeDef bsp_ds18b20_get_temp(float *temp_out) { - bsp_ds18b20_reset_bus(); + bsp_ds18b20_reset_bus(); HAL_StatusTypeDef res = bsp_ds18b20_check_present(); if (res != HAL_OK) { return res; } - bsp_ds18b20_write_byte(0xCC); //跳过ROM - bsp_ds18b20_write_byte(0xBE); //读Scratchpad - uint8_t temp_lsb = bsp_ds18b20_read_byte(); //Scratchpad第0字节 温度LSB - uint8_t temp_msb = bsp_ds18b20_read_byte(); //Scratchpad第1字节 温度MSB + bsp_ds18b20_write_byte(0xCC); //跳过ROM + bsp_ds18b20_write_byte(0xBE); //读Scratchpad + uint8_t temp_lsb = bsp_ds18b20_read_byte(); //Scratchpad第0字节 温度LSB + uint8_t temp_msb = bsp_ds18b20_read_byte(); //Scratchpad第1字节 温度MSB - if(temp_msb & 0x80) { //温度为负 + if(temp_msb & 0x80) { //温度为负 int16_t temp = (~temp_msb) << 8 | (~temp_lsb); //转换为正数 *temp_out = -0.0625f * temp; //输出负数 - } else { //温度为正 + } else { //温度为正 int16_t temp = temp_msb << 8 | temp_lsb; *temp_out = 0.0625f * temp; //12位转换精度 每LSB等于0.0625度 - } + } return HAL_OK; } diff --git a/stm32f0_clock/Bsp/Src/bsp_ds3231.c b/stm32f0_clock/Bsp/Src/bsp_ds3231.c index 46b7713..0ec72f3 100644 --- a/stm32f0_clock/Bsp/Src/bsp_ds3231.c +++ b/stm32f0_clock/Bsp/Src/bsp_ds3231.c @@ -4,11 +4,11 @@ HAL_StatusTypeDef bsp_ds3231_update_time(uint8_t hour, uint8_t minute, uint8_t second) { uint8_t write_buffer[3]; - + if (second >= 60 || minute >= 60 || hour >= 24) { return HAL_ERROR; } - + write_buffer[0] = (second % 10) * 0x01 | (second / 10) * 0x10; write_buffer[1] = (minute % 10) * 0x01 | (minute / 10) * 0x10; write_buffer[2] = (hour % 10) * 0x01 | (hour / 10) * 0x10; //24小时模式 @@ -19,28 +19,28 @@ HAL_StatusTypeDef bsp_ds3231_update_time(uint8_t hour, uint8_t minute, uint8_t s HAL_StatusTypeDef bsp_ds3231_update_date(uint8_t day_of_week, uint8_t year, uint8_t month, uint8_t date) { uint8_t write_buffer[4]; - + if (day_of_week > 7 || day_of_week == 0 || date > 31 || date == 0 || month > 12 || month == 0 || year > 99) { return HAL_ERROR; } - + write_buffer[0] = day_of_week; write_buffer[1] = (date % 10) * 0x01 | (date / 10) * 0x10; write_buffer[2] = (1 << 7) | ((month % 10) * 0x01 | (month / 10) * 0x10); //月份寄存器的最高位是世纪标志位 write_buffer[3] = (year % 10) * 0x01 | (year / 10) * 0x10; - + return HAL_I2C_Mem_Write(&hi2c1, 0x68 << 1, 0x03, 1, write_buffer, sizeof(write_buffer), 200); //写寄存器0x03-0x06 } HAL_StatusTypeDef bsp_ds3231_update_time_date(const ds3231_date_time_info_t *info) { uint8_t write_buffer[7]; - + if (info->second >= 60 || info->minute >= 60 || info->hour >= 24 || info->day_of_week > 7 || info->day_of_week == 0 || info->date > 31 || info->date == 0 || info->month > 12 || info->month == 0 || info->year > 99) { return HAL_ERROR; } - + write_buffer[0] = (info->second % 10) * 0x01 | (info->second / 10) * 0x10; write_buffer[1] = (info->minute % 10) * 0x01 | (info->minute / 10) * 0x10; write_buffer[2] = (info->hour % 10) * 0x01 | (info->hour / 10) * 0x10; //24小时模式 @@ -48,7 +48,7 @@ HAL_StatusTypeDef bsp_ds3231_update_time_date(const ds3231_date_time_info_t *inf write_buffer[4] = (info->date % 10) * 0x01 | (info->date / 10) * 0x10; write_buffer[5] = (1 << 7) | ((info->month % 10) * 0x01 | (info->month / 10) * 0x10); //月份寄存器的最高位是世纪标志位 write_buffer[6] = (info->year % 10) * 0x01 | (info->year / 10) * 0x10; - + return HAL_I2C_Mem_Write(&hi2c1, 0x68 << 1, 0x00, 1, write_buffer, sizeof(write_buffer), 200); //写寄存器0x00-0x06 } @@ -61,7 +61,7 @@ HAL_StatusTypeDef bsp_ds3231_get_time_date(ds3231_date_time_info_t *info) if (res != HAL_OK) { return res; } - + //秒 bcd_low = read_buffer[0] & 0x0F; bcd_high = (read_buffer[0] & 0x70) >> 4; info->second = bcd_low + bcd_high * 10; @@ -87,47 +87,47 @@ HAL_StatusTypeDef bsp_ds3231_get_time_date(ds3231_date_time_info_t *info) //年 bcd_low = read_buffer[6] & 0x0F; bcd_high = (read_buffer[6] & 0xF0) >> 4; info->year = bcd_low + bcd_high * 10; - + return HAL_OK; } HAL_StatusTypeDef bsp_ds3231_init(void) { uint8_t read_write_buffer[2]; - + read_write_buffer[0] = 0x00; //电池供电时使能振荡器 方波输出频率1Hz 关闭电池供电时的时钟输出 关闭闹钟中断输出 read_write_buffer[1] = 0x00; //关闭时钟输出 - + HAL_StatusTypeDef res = HAL_I2C_Mem_Write(&hi2c1, 0x68 << 1, 0x0E, 1, read_write_buffer, 2, 200); //写寄存器0x0E-0x0F if (res != HAL_OK) { return res; } - + res = HAL_I2C_Mem_Read(&hi2c1, 0x68 << 1, 0x02, 1, read_write_buffer, 1, 200); //读寄存器0x02 if (res != HAL_OK) { return res; } if (read_write_buffer[0] & (1 << 6)) { read_write_buffer[0] &= ~(1 << 6); //切换至默认的24小时制 - + res = HAL_I2C_Mem_Write(&hi2c1, 0x68 << 1, 0x02, 1, read_write_buffer, 1, 200); //写回寄存器0x02 if (res != HAL_OK) { return res; } } - + res = HAL_I2C_Mem_Read(&hi2c1, 0x68 << 1, 0x05, 1, read_write_buffer, 1, 200); //读寄存器0x05 if (res != HAL_OK) { return res; } if ((read_write_buffer[0] & (1 << 7)) == 0x00) { read_write_buffer[0] |= (1 << 7); //切换世纪位为1 - + res = HAL_I2C_Mem_Write(&hi2c1, 0x68 << 1, 0x05, 1, read_write_buffer, 1, 200); //写回寄存器0x05 if (res != HAL_OK) { return res; } } - + return HAL_OK; } diff --git a/stm32f0_clock/Bsp/Src/bsp_key.c b/stm32f0_clock/Bsp/Src/bsp_key.c index 1c8b200..a69ca10 100644 --- a/stm32f0_clock/Bsp/Src/bsp_key.c +++ b/stm32f0_clock/Bsp/Src/bsp_key.c @@ -10,10 +10,10 @@ typedef enum { struct { volatile bsp_key_value_e pressed_key; volatile bsp_key_value_e last_key; - + volatile uint8_t long_press_cnt; volatile uint8_t long_pressed; - + volatile bsp_key_event_e key_event; } bsp_key_status = { .pressed_key = bsp_key_value_none, @@ -72,11 +72,11 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) bsp_key_event_e bsp_key_get_event(void) { bsp_key_event_e event_ret = bsp_key_none; - + if (bsp_key_status.key_event != bsp_key_none) { event_ret = bsp_key_status.key_event; bsp_key_status.key_event = bsp_key_none; } - + return event_ret; } diff --git a/stm32f0_clock/Core/Src/app_main.c b/stm32f0_clock/Core/Src/app_main.c index e19d64b..6fe0205 100644 --- a/stm32f0_clock/Core/Src/app_main.c +++ b/stm32f0_clock/Core/Src/app_main.c @@ -64,7 +64,7 @@ void app_main(void) } bsp_key_event_e key_event = bsp_key_get_event(); - + switch (key_event) { case bsp_key_up_short: bsp_buzzer_play_note(H1); @@ -100,7 +100,7 @@ void app_main(void) bsp_buzzer_play_note(STOP); break; } - + counter ++; HAL_Delay(1); }