shit-202408082000
This commit is contained in:
parent
f526aa2b8f
commit
ea9e742e72
@ -1,30 +1,35 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "gd32e23x.h"
|
#include "gd32e23x.h"
|
||||||
#include "systick.h"
|
#include "systick.h"
|
||||||
|
|
||||||
#include "chirp_smartsonic.h"
|
#include "chirp_smartsonic.h"
|
||||||
#include "soniclib.h"
|
|
||||||
#include "chirp_bsp.h"
|
|
||||||
|
|
||||||
#include "board_init.h"
|
|
||||||
#include "chirp_board_config.h"
|
#include "chirp_board_config.h"
|
||||||
|
|
||||||
#include "app_config.h"
|
/*!
|
||||||
|
\brief LED Turn On
|
||||||
|
\param[in] none
|
||||||
|
\param[out] none
|
||||||
|
\retval none
|
||||||
|
*/
|
||||||
void sensor_led_on(void) {
|
void sensor_led_on(void) {
|
||||||
gpio_bit_reset(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN); // PB1 = Lo LED = On
|
gpio_bit_reset(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN); // PB1 = Lo LED = On
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief LED Turn Off
|
||||||
|
\param[in] none
|
||||||
|
\param[out] none
|
||||||
|
\retval none
|
||||||
|
*/
|
||||||
void sensor_led_off(void) {
|
void sensor_led_off(void) {
|
||||||
gpio_bit_set(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN); // PB1 = Hi LED = Off
|
gpio_bit_set(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN); // PB1 = Hi LED = Off
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief LED Toggle
|
||||||
|
\param[in] none
|
||||||
|
\param[out] none
|
||||||
|
\retval none
|
||||||
|
*/
|
||||||
void sensor_led_toggle(void)
|
void sensor_led_toggle(void)
|
||||||
{
|
{
|
||||||
gpio_bit_toggle(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN);
|
gpio_bit_toggle(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN);
|
||||||
|
@ -38,7 +38,7 @@ static void measure_idd(uint16_t nb_measure){
|
|||||||
}
|
}
|
||||||
#elif
|
#elif
|
||||||
static void measure_idd(uint16_t nb_measure){
|
static void measure_idd(uint16_t nb_measure){
|
||||||
|
__NOP();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -95,7 +95,6 @@ static void find_sensors(void)
|
|||||||
} else {
|
} else {
|
||||||
printf("not found!\n");
|
printf("not found!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_bit_reset(CHIRP_PIN_PROG_PORT, CHIRP_PIN_PROG_PIN);
|
gpio_bit_reset(CHIRP_PIN_PROG_PORT, CHIRP_PIN_PROG_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,19 +148,13 @@ void chbsp_board_init(ch_group_t *grp_ptr) {
|
|||||||
grp_ptr->num_i2c_buses = CHIRP_NUM_I2C_BUSES;
|
grp_ptr->num_i2c_buses = CHIRP_NUM_I2C_BUSES;
|
||||||
grp_ptr->rtc_cal_pulse_ms = CHBSP_RTC_CAL_PULSE_MS;
|
grp_ptr->rtc_cal_pulse_ms = CHBSP_RTC_CAL_PULSE_MS;
|
||||||
|
|
||||||
/* Initialize the GD32 system. */
|
|
||||||
// systick_config();
|
|
||||||
board_init_I2C();
|
board_init_I2C();
|
||||||
|
|
||||||
configure_console();
|
configure_console();
|
||||||
|
|
||||||
ADC0_init();
|
ADC0_init();
|
||||||
ext_int_init();
|
ext_int_init();
|
||||||
|
|
||||||
/* Probe I2C bus to find connected sensor(s) */
|
/* Probe I2C bus to find connected sensor(s) */
|
||||||
find_sensors();
|
find_sensors();
|
||||||
measure_power();
|
measure_power();
|
||||||
|
|
||||||
indicate_alive();
|
indicate_alive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,5 @@ uint8_t ultrasound_display_config_info(ch_dev_t *dev_ptr)
|
|||||||
} else {
|
} else {
|
||||||
printf(" Device %d: Error during ch_get_config()\n", dev_num);
|
printf(" Device %d: Error during ch_get_config()\n", dev_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
return chirp_error;
|
return chirp_error;
|
||||||
}
|
}
|
@ -68,28 +68,18 @@ void configure_console(void)
|
|||||||
*/
|
*/
|
||||||
void i2c_bus_reset(void)
|
void i2c_bus_reset(void)
|
||||||
{
|
{
|
||||||
i2c_deinit(I2C0);
|
i2c_deinit(I2C0);
|
||||||
/* configure SDA/SCL for GPIO */
|
/* configure SDA/SCL for GPIO */
|
||||||
GPIO_BC(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SDA_PIN;
|
GPIO_BC(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SDA_PIN;
|
||||||
GPIO_BC(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SCL_PIN;
|
GPIO_BC(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SCL_PIN;
|
||||||
gpio_output_options_set(CHIRP_PIN_IIC_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, CHIRP_PIN_IIC_SDA_PIN);
|
gpio_output_options_set(CHIRP_PIN_IIC_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, CHIRP_PIN_IIC_SDA_PIN);
|
||||||
gpio_output_options_set(CHIRP_PIN_IIC_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, CHIRP_PIN_IIC_SCL_PIN);
|
gpio_output_options_set(CHIRP_PIN_IIC_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, CHIRP_PIN_IIC_SCL_PIN);
|
||||||
__NOP();
|
__NOP();__NOP();__NOP();__NOP();__NOP();
|
||||||
__NOP();
|
GPIO_BOP(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SCL_PIN;
|
||||||
__NOP();
|
__NOP();__NOP();__NOP();__NOP();__NOP();
|
||||||
__NOP();
|
GPIO_BOP(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SDA_PIN;
|
||||||
__NOP();
|
gpio_output_options_set(CHIRP_PIN_IIC_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, CHIRP_PIN_IIC_SCL_PIN);
|
||||||
GPIO_BOP(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SCL_PIN;
|
gpio_output_options_set(CHIRP_PIN_IIC_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, CHIRP_PIN_IIC_SDA_PIN);
|
||||||
__NOP();
|
/* configure the I2CX interface */
|
||||||
__NOP();
|
i2c_master_init();
|
||||||
__NOP();
|
|
||||||
__NOP();
|
|
||||||
__NOP();
|
|
||||||
GPIO_BOP(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SDA_PIN;
|
|
||||||
/* connect I2C_SCL_PIN to I2C_SCL */
|
|
||||||
/* connect I2C_SDA_PIN to I2C_SDA */
|
|
||||||
gpio_output_options_set(CHIRP_PIN_IIC_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, CHIRP_PIN_IIC_SCL_PIN);
|
|
||||||
gpio_output_options_set(CHIRP_PIN_IIC_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, CHIRP_PIN_IIC_SDA_PIN);
|
|
||||||
/* configure the I2CX interface */
|
|
||||||
i2c_master_init();
|
|
||||||
}
|
}
|
@ -70,12 +70,10 @@ typedef struct {
|
|||||||
uint16_t amplitude; // from ch_get_amplitude()
|
uint16_t amplitude; // from ch_get_amplitude()
|
||||||
uint16_t num_samples; // from ch_get_num_samples()
|
uint16_t num_samples; // from ch_get_num_samples()
|
||||||
#ifdef READ_AMPLITUDE_DATA
|
#ifdef READ_AMPLITUDE_DATA
|
||||||
uint16_t amp_data[DATA_MAX_NUM_SAMPLES];
|
uint16_t amp_data[DATA_MAX_NUM_SAMPLES]; // from ch_get_amplitude_data()
|
||||||
// from ch_get_amplitude_data()
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef READ_IQ_DATA
|
#ifdef READ_IQ_DATA
|
||||||
ch_iq_sample_t iq_data[DATA_MAX_NUM_SAMPLES];
|
ch_iq_sample_t iq_data[DATA_MAX_NUM_SAMPLES]; // from ch_get_iq_data()
|
||||||
// from ch_get_iq_data()
|
|
||||||
#endif
|
#endif
|
||||||
} chirp_data_t;
|
} chirp_data_t;
|
||||||
|
|
||||||
@ -148,12 +146,18 @@ int main(void)
|
|||||||
printf(" SonicLib version: %u.%u.%u\n", SONICLIB_VER_MAJOR, SONICLIB_VER_MINOR, SONICLIB_VER_REV);
|
printf(" SonicLib version: %u.%u.%u\n", SONICLIB_VER_MAJOR, SONICLIB_VER_MINOR, SONICLIB_VER_REV);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
#ifdef DEBUG_VERBOES
|
||||||
/* print out the clock frequency of system, AHB, APB1 and APB2 */
|
/* print out the clock frequency of system, AHB, APB1 and APB2 */
|
||||||
|
printf("[DebugVerboes] System CLK Info!!!");
|
||||||
printf("\r\nCK_SYS is %d", rcu_clock_freq_get(CK_SYS));
|
printf("\r\nCK_SYS is %d", rcu_clock_freq_get(CK_SYS));
|
||||||
printf("\r\nCK_AHB is %d", rcu_clock_freq_get(CK_AHB));
|
printf("\r\nCK_AHB is %d", rcu_clock_freq_get(CK_AHB));
|
||||||
printf("\r\nCK_APB1 is %d", rcu_clock_freq_get(CK_APB1));
|
printf("\r\nCK_APB1 is %d", rcu_clock_freq_get(CK_APB1));
|
||||||
printf("\r\nCK_APB2 is %d", rcu_clock_freq_get(CK_APB2));
|
printf("\r\nCK_APB2 is %d", rcu_clock_freq_get(CK_APB2));
|
||||||
|
printf("[DebugVerboes] System CLK Info Done!!!");
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
|
printf("\r\n");
|
||||||
|
printf("\r\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Get the number of sensor devices on the board*/
|
/* Get the number of sensor devices on the board*/
|
||||||
num_ports = ch_get_num_ports(grp_ptr);
|
num_ports = ch_get_num_ports(grp_ptr);
|
||||||
@ -178,7 +182,6 @@ int main(void)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("Sensor\tType \t Freq\t\t RTC Cal \tFirmware\n");
|
printf("Sensor\tType \t Freq\t\t RTC Cal \tFirmware\n");
|
||||||
|
|
||||||
for (dev_num = 0; dev_num < num_ports; dev_num++) {
|
for (dev_num = 0; dev_num < num_ports; dev_num++) {
|
||||||
ch_dev_t *dev_ptr = ch_get_dev_ptr(grp_ptr, dev_num);
|
ch_dev_t *dev_ptr = ch_get_dev_ptr(grp_ptr, dev_num);
|
||||||
|
|
||||||
@ -263,30 +266,26 @@ int main(void)
|
|||||||
// * handler when the interrupt occurs. The callback function will be
|
// * handler when the interrupt occurs. The callback function will be
|
||||||
// * used to trigger a measurement cycle on the group of sensors.
|
// * used to trigger a measurement cycle on the group of sensors.
|
||||||
// */
|
// */
|
||||||
// if (num_triggered_devices > 0) {
|
if (num_triggered_devices > 0) {
|
||||||
// printf("Initializing sample timer for %dms interval... ", MEASUREMENT_INTERVAL_MS);
|
printf("Initializing sample timer for %dms interval... ", MEASUREMENT_INTERVAL_MS);
|
||||||
|
|
||||||
// chbsp_periodic_timer_init(MEASUREMENT_INTERVAL_MS, periodic_timer_callback);
|
// chbsp_periodic_timer_init(MEASUREMENT_INTERVAL_MS, periodic_timer_callback);
|
||||||
|
/* Enable interrupt and start timer to trigger sensor sampling */
|
||||||
// /* Enable interrupt and start timer to trigger sensor sampling */
|
|
||||||
// chbsp_periodic_timer_irq_enable();
|
// chbsp_periodic_timer_irq_enable();
|
||||||
// chbsp_periodic_timer_start();
|
// chbsp_periodic_timer_start();
|
||||||
|
printf("OK\n");
|
||||||
// printf("OK\n");
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
printf("Starting measurements\n");
|
printf("Starting measurements\n");
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
handle_data_ready(grp_ptr);
|
handle_data_ready(grp_ptr);
|
||||||
gpio_bit_toggle(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN);
|
chbsp_led_toggle(dev_num);
|
||||||
delay_ms(TestDelayTime);
|
delay_ms(MEASUREMENT_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* periodic_timer_callback() - periodic timer callback routine
|
* periodic_timer_callback() - periodic timer callback routine
|
||||||
*
|
*
|
||||||
@ -425,7 +424,6 @@ static uint8_t handle_data_ready(ch_group_t *grp_ptr) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Target object was successfully detected (range available) */
|
/* Target object was successfully detected (range available) */
|
||||||
|
|
||||||
/* Get the new amplitude value - it's only updated if range
|
/* Get the new amplitude value - it's only updated if range
|
||||||
* was successfully measured. */
|
* was successfully measured. */
|
||||||
chirp_data[dev_num].amplitude = ch_get_amplitude(dev_ptr);
|
chirp_data[dev_num].amplitude = ch_get_amplitude(dev_ptr);
|
||||||
|
@ -32,7 +32,6 @@ void systick_config(void)
|
|||||||
count_1ms = (float)count_1us * 1000;
|
count_1ms = (float)count_1us * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ************************************************************************
|
* ************************************************************************
|
||||||
* @brief delay_us 微秒延时函数
|
* @brief delay_us 微秒延时函数
|
||||||
@ -60,10 +59,8 @@ void delay_us(uint32_t count)
|
|||||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||||
//将 SysTick 计数器的当前值清零,以便下次使用
|
//将 SysTick 计数器的当前值清零,以便下次使用
|
||||||
SysTick->VAL = 0x0000U;
|
SysTick->VAL = 0x0000U;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ************************************************************************
|
* ************************************************************************
|
||||||
* @brief delay_ms 毫秒延时函数
|
* @brief delay_ms 毫秒延时函数
|
||||||
|
Loading…
x
Reference in New Issue
Block a user