shit-202408082000
This commit is contained in:
parent
f526aa2b8f
commit
ea9e742e72
@ -1,30 +1,35 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
|
||||
#include "chirp_smartsonic.h"
|
||||
#include "soniclib.h"
|
||||
#include "chirp_bsp.h"
|
||||
|
||||
#include "board_init.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) {
|
||||
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) {
|
||||
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)
|
||||
{
|
||||
gpio_bit_toggle(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN);
|
||||
|
@ -38,7 +38,7 @@ static void measure_idd(uint16_t nb_measure){
|
||||
}
|
||||
#elif
|
||||
static void measure_idd(uint16_t nb_measure){
|
||||
|
||||
__NOP();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -95,7 +95,6 @@ static void find_sensors(void)
|
||||
} else {
|
||||
printf("not found!\n");
|
||||
}
|
||||
|
||||
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->rtc_cal_pulse_ms = CHBSP_RTC_CAL_PULSE_MS;
|
||||
|
||||
/* Initialize the GD32 system. */
|
||||
// systick_config();
|
||||
board_init_I2C();
|
||||
|
||||
configure_console();
|
||||
|
||||
ADC0_init();
|
||||
ext_int_init();
|
||||
|
||||
/* Probe I2C bus to find connected sensor(s) */
|
||||
find_sensors();
|
||||
measure_power();
|
||||
|
||||
indicate_alive();
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,5 @@ uint8_t ultrasound_display_config_info(ch_dev_t *dev_ptr)
|
||||
} else {
|
||||
printf(" Device %d: Error during ch_get_config()\n", dev_num);
|
||||
}
|
||||
|
||||
return chirp_error;
|
||||
}
|
@ -68,28 +68,18 @@ void configure_console(void)
|
||||
*/
|
||||
void i2c_bus_reset(void)
|
||||
{
|
||||
i2c_deinit(I2C0);
|
||||
/* 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_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_SCL_PIN);
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
GPIO_BOP(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SCL_PIN;
|
||||
__NOP();
|
||||
__NOP();
|
||||
__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();
|
||||
i2c_deinit(I2C0);
|
||||
/* 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_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_SCL_PIN);
|
||||
__NOP();__NOP();__NOP();__NOP();__NOP();
|
||||
GPIO_BOP(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SCL_PIN;
|
||||
__NOP();__NOP();__NOP();__NOP();__NOP();
|
||||
GPIO_BOP(CHIRP_PIN_IIC_PORT) |= CHIRP_PIN_IIC_SDA_PIN;
|
||||
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 num_samples; // from ch_get_num_samples()
|
||||
#ifdef READ_AMPLITUDE_DATA
|
||||
uint16_t amp_data[DATA_MAX_NUM_SAMPLES];
|
||||
// from ch_get_amplitude_data()
|
||||
uint16_t amp_data[DATA_MAX_NUM_SAMPLES]; // from ch_get_amplitude_data()
|
||||
#endif
|
||||
#ifdef READ_IQ_DATA
|
||||
ch_iq_sample_t iq_data[DATA_MAX_NUM_SAMPLES];
|
||||
// from ch_get_iq_data()
|
||||
ch_iq_sample_t iq_data[DATA_MAX_NUM_SAMPLES]; // from ch_get_iq_data()
|
||||
#endif
|
||||
} 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("\n");
|
||||
|
||||
#ifdef DEBUG_VERBOES
|
||||
/* 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_AHB is %d", rcu_clock_freq_get(CK_AHB));
|
||||
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("[DebugVerboes] System CLK Info Done!!!");
|
||||
printf("\r\n");
|
||||
printf("\r\n");
|
||||
printf("\r\n");
|
||||
#endif
|
||||
|
||||
/* Get the number of sensor devices on the board*/
|
||||
num_ports = ch_get_num_ports(grp_ptr);
|
||||
@ -178,7 +182,6 @@ int main(void)
|
||||
printf("\n");
|
||||
|
||||
printf("Sensor\tType \t Freq\t\t RTC Cal \tFirmware\n");
|
||||
|
||||
for (dev_num = 0; dev_num < num_ports; 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
|
||||
// * used to trigger a measurement cycle on the group of sensors.
|
||||
// */
|
||||
// if (num_triggered_devices > 0) {
|
||||
// printf("Initializing sample timer for %dms interval... ", MEASUREMENT_INTERVAL_MS);
|
||||
if (num_triggered_devices > 0) {
|
||||
printf("Initializing sample timer for %dms interval... ", MEASUREMENT_INTERVAL_MS);
|
||||
|
||||
// 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_start();
|
||||
|
||||
// printf("OK\n");
|
||||
// }
|
||||
|
||||
printf("OK\n");
|
||||
}
|
||||
printf("Starting measurements\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
handle_data_ready(grp_ptr);
|
||||
gpio_bit_toggle(CHIRP_PIN_LED_PORT, CHIRP_PIN_LED_PIN);
|
||||
delay_ms(TestDelayTime);
|
||||
chbsp_led_toggle(dev_num);
|
||||
delay_ms(MEASUREMENT_INTERVAL_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* periodic_timer_callback() - periodic timer callback routine
|
||||
*
|
||||
@ -425,7 +424,6 @@ static uint8_t handle_data_ready(ch_group_t *grp_ptr) {
|
||||
|
||||
} else {
|
||||
/* Target object was successfully detected (range available) */
|
||||
|
||||
/* Get the new amplitude value - it's only updated if range
|
||||
* was successfully measured. */
|
||||
chirp_data[dev_num].amplitude = ch_get_amplitude(dev_ptr);
|
||||
|
@ -32,7 +32,6 @@ void systick_config(void)
|
||||
count_1ms = (float)count_1us * 1000;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ************************************************************************
|
||||
* @brief delay_us 微秒延时函数
|
||||
@ -60,10 +59,8 @@ void delay_us(uint32_t count)
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
//将 SysTick 计数器的当前值清零,以便下次使用
|
||||
SysTick->VAL = 0x0000U;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ************************************************************************
|
||||
* @brief delay_ms 毫秒延时函数
|
||||
|
Loading…
x
Reference in New Issue
Block a user