60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
#include "user_main.h"
|
|
|
|
#define ADC_SAMPLE_NUM 16384
|
|
|
|
uint8_t fsmc_read_buf, fsmc_write_buf;
|
|
int8_t adc_result[ADC_SAMPLE_NUM];
|
|
|
|
void user_setup()
|
|
{
|
|
flash_fpga();
|
|
// ethernet_init();
|
|
HAL_TIM_Base_Start_IT(&htim4);
|
|
HAL_TIM_Base_Start(&htim3);
|
|
eem_power_init();
|
|
uint8_t str[10] = "start";
|
|
HAL_UART_Transmit(&huart4, str, 6, 100);
|
|
|
|
HAL_GPIO_WritePin(GND1_SW_GPIO_Port, GND1_SW_Pin, GPIO_PIN_SET);
|
|
HAL_GPIO_WritePin(GND2_SW_GPIO_Port, GND2_SW_Pin, GPIO_PIN_SET);
|
|
}
|
|
|
|
uint8_t dio_ch = 0;
|
|
uint8_t dio_io = 0;
|
|
uint8_t adc_sample = 0;
|
|
uint16_t fsmc_add = 0;
|
|
void user_loop()
|
|
{
|
|
if (adc_sample)
|
|
{
|
|
adc_sample = 0;
|
|
fsmc_write_buf = (dio_io & 0x01) | ((dio_ch & 0x03) << 1) | 0x10;
|
|
fsmc_write(fsmc_write_buf, 0);
|
|
}
|
|
// fsmc_read(0xffff, (uint8_t*)&fsmc_read_buf);
|
|
// if (fsmc_read_buf & 0x02)
|
|
if (HAL_GPIO_ReadPin(FSMC_NWAIT_GPIO_Port, FSMC_NWAIT_Pin) == GPIO_PIN_SET)
|
|
{
|
|
fsmc_write_buf = (dio_io & 0x01) | ((dio_ch & 0x03) << 1);
|
|
fsmc_write(fsmc_write_buf, 0);
|
|
fsmc_add = 0;
|
|
while (fsmc_add < ADC_SAMPLE_NUM)
|
|
{
|
|
fsmc_read(fsmc_add, (uint8_t*)(adc_result + fsmc_add));
|
|
fsmc_add++;
|
|
}
|
|
// HAL_UART_Transmit(&huart4, "test0", 6, 100);
|
|
HAL_UART_Transmit(&huart4, (uint8_t*)adc_result, ADC_SAMPLE_NUM, 10000);
|
|
}
|
|
// HAL_Delay(1000);
|
|
// key_events();
|
|
if (HAL_GPIO_ReadPin(KEY_GPIO_Port, KEY_Pin) == GPIO_PIN_RESET)
|
|
{
|
|
HAL_Delay(50);
|
|
if (HAL_GPIO_ReadPin(KEY_GPIO_Port, KEY_Pin) == GPIO_PIN_RESET)
|
|
{
|
|
adc_sample = 1;
|
|
while (HAL_GPIO_ReadPin(KEY_GPIO_Port, KEY_Pin) == GPIO_PIN_RESET);
|
|
}
|
|
}
|
|
} |