stm32f0_clock: convert tabs to spaces
This commit is contained in:
parent
7e37a19f22
commit
66bc316c6b
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user