preparations for changing gps library
This commit is contained in:
parent
ed5c7f46f3
commit
fde157dd0d
@ -16,5 +16,6 @@ int gps_init(void);
|
|||||||
void gps_read(void);
|
void gps_read(void);
|
||||||
void gps_loop(void *pvParameters);
|
void gps_loop(void *pvParameters);
|
||||||
time_t get_gpstime(void);
|
time_t get_gpstime(void);
|
||||||
|
int gps_config();
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -15,8 +15,8 @@
|
|||||||
;env_default = ttgov2
|
;env_default = ttgov2
|
||||||
;env_default = ttgov21old
|
;env_default = ttgov21old
|
||||||
;env_default = ttgov21new
|
;env_default = ttgov21new
|
||||||
env_default = ttgobeam
|
;env_default = ttgobeam
|
||||||
;env_default = ttgofox
|
env_default = ttgofox
|
||||||
;env_default = lopy
|
;env_default = lopy
|
||||||
;env_default = lopy4
|
;env_default = lopy4
|
||||||
;env_default = fipy
|
;env_default = fipy
|
||||||
@ -50,6 +50,7 @@ lib_deps_rgbled =
|
|||||||
SmartLeds@>=1.1.5
|
SmartLeds@>=1.1.5
|
||||||
lib_deps_gps =
|
lib_deps_gps =
|
||||||
TinyGPSPlus@>=1.0.2
|
TinyGPSPlus@>=1.0.2
|
||||||
|
; NeoGPS^4.2.9
|
||||||
lib_deps_rtc =
|
lib_deps_rtc =
|
||||||
RTC@^2.3.0
|
RTC@^2.3.0
|
||||||
lib_deps_basic =
|
lib_deps_basic =
|
||||||
@ -222,6 +223,7 @@ build_flags =
|
|||||||
upload_protocol = ${common.upload_protocol}
|
upload_protocol = ${common.upload_protocol}
|
||||||
extra_scripts = ${common.extra_scripts}
|
extra_scripts = ${common.extra_scripts}
|
||||||
monitor_speed = ${common.monitor_speed}
|
monitor_speed = ${common.monitor_speed}
|
||||||
|
upload_port = COM61
|
||||||
|
|
||||||
[env:ttgobeam]
|
[env:ttgobeam]
|
||||||
platform = ${common.platform_espressif32}
|
platform = ${common.platform_espressif32}
|
||||||
|
@ -20,8 +20,11 @@ static const char TAG[] = "main";
|
|||||||
#define DCF77_FRAME_SIZE (60)
|
#define DCF77_FRAME_SIZE (60)
|
||||||
#define DCF77_PULSE_DURATION (100)
|
#define DCF77_PULSE_DURATION (100)
|
||||||
|
|
||||||
|
// select internal / external clock
|
||||||
#if defined RTC_INT && defined RTC_CLK
|
#if defined RTC_INT && defined RTC_CLK
|
||||||
#define PPS RTC_CLK
|
#define PPS RTC_CLK
|
||||||
|
#elif defined GPS_INT && defined GPS_CLK
|
||||||
|
#define PPS GPS_CLK
|
||||||
#else
|
#else
|
||||||
#define PPS DCF77_PULSE_DURATION
|
#define PPS DCF77_PULSE_DURATION
|
||||||
#endif
|
#endif
|
||||||
@ -127,13 +130,16 @@ void dcf77_loop(void *pvParameters) {
|
|||||||
&wakeTime, // receives moment of call from isr
|
&wakeTime, // receives moment of call from isr
|
||||||
portMAX_DELAY); // wait forever (missing error handling here...)
|
portMAX_DELAY); // wait forever (missing error handling here...)
|
||||||
|
|
||||||
|
// select clock scale
|
||||||
#if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling
|
#if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling
|
||||||
DCF_Out(0);
|
DCF_Out(0);
|
||||||
|
|
||||||
#elif (PPS > DCF77_PULSE_DURATION) // we need upclocking
|
#elif (PPS > DCF77_PULSE_DURATION) // we need upclocking
|
||||||
for (uint8_t i = 1; i <= PPS / DCF77_PULSE_DURATION; i++) {
|
for (uint8_t i = 1; i <= PPS / DCF77_PULSE_DURATION; i++) {
|
||||||
DCF_Out(0);
|
DCF_Out(0);
|
||||||
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION));
|
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif (PPS < DCF77_PULSE_DURATION) // we need downclocking
|
#elif (PPS < DCF77_PULSE_DURATION) // we need downclocking
|
||||||
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION - PPS));
|
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION - PPS));
|
||||||
DCF_Out(0);
|
DCF_Out(0);
|
||||||
|
@ -18,6 +18,11 @@ int gps_init(void) {
|
|||||||
|
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
|
if (!gps_config()) {
|
||||||
|
ESP_LOGE(TAG, "GPS chip initializiation error");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined GPS_SERIAL
|
#if defined GPS_SERIAL
|
||||||
GPS_Serial.begin(GPS_SERIAL);
|
GPS_Serial.begin(GPS_SERIAL);
|
||||||
ESP_LOGI(TAG, "Using serial GPS");
|
ESP_LOGI(TAG, "Using serial GPS");
|
||||||
@ -41,6 +46,21 @@ int gps_init(void) {
|
|||||||
return ret;
|
return ret;
|
||||||
} // gps_init()
|
} // gps_init()
|
||||||
|
|
||||||
|
// detect gps chipset type and configure it with device specific settings
|
||||||
|
int gps_config() {
|
||||||
|
int rslt = 1; // success
|
||||||
|
#if defined GPS_SERIAL
|
||||||
|
|
||||||
|
/* to come */
|
||||||
|
|
||||||
|
#elif defined GPS_I2C
|
||||||
|
|
||||||
|
/* to come */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
|
|
||||||
// read GPS data and cast to global struct
|
// read GPS data and cast to global struct
|
||||||
void gps_read() {
|
void gps_read() {
|
||||||
gps_status.latitude = (int32_t)(gps.location.lat() * 1e6);
|
gps_status.latitude = (int32_t)(gps.location.lat() * 1e6);
|
||||||
@ -73,8 +93,8 @@ time_t get_gpstime(void) {
|
|||||||
if ((gps.time.age() < 1500) && (gps.time.isValid())) {
|
if ((gps.time.age() < 1500) && (gps.time.isValid())) {
|
||||||
t = tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(),
|
t = tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(),
|
||||||
gps.time.hour(), gps.time.minute(), gps.time.second());
|
gps.time.hour(), gps.time.minute(), gps.time.second());
|
||||||
ESP_LOGD(TAG, "GPS time: %4d/%02d/%02d %02d:%02d:%02d", year(t), month(t), day(t),
|
ESP_LOGD(TAG, "GPS time: %4d/%02d/%02d %02d:%02d:%02d", year(t), month(t),
|
||||||
hour(t), minute(t), second(t));
|
day(t), hour(t), minute(t), second(t));
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "GPS has no confident time");
|
ESP_LOGW(TAG, "GPS has no confident time");
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,14 @@
|
|||||||
#define HAS_BUTTON GPIO_NUM_39 // on board button (next to reset)
|
#define HAS_BUTTON GPIO_NUM_39 // on board button (next to reset)
|
||||||
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||||
#define BATT_FACTOR 2 // voltage divider 100k/100k on board
|
#define BATT_FACTOR 2 // voltage divider 100k/100k on board
|
||||||
|
|
||||||
|
// GPS settings
|
||||||
#define HAS_GPS 1 // use on board GPS
|
#define HAS_GPS 1 // use on board GPS
|
||||||
#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_12, GPIO_NUM_15 // UBlox NEO 6M or 7M with default configuration
|
#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_12, GPIO_NUM_15 // UBlox NEO 6M or 7M with default configuration
|
||||||
|
// to use
|
||||||
|
#define GPS_INT GPIO_NUM_34 // 30ns accurary timepulse, to be external wired on pcb: R34 -> GPIO34
|
||||||
|
// 1 pulse per second, synchronized at rising edge, pulse length 100ms, accuracy +/- 3 *e-8 [nanoseconds] = 0,95sec / year
|
||||||
|
#define GPS_CLK (1000)
|
||||||
|
|
||||||
// enable only if device has these sensors, otherwise comment these lines
|
// enable only if device has these sensors, otherwise comment these lines
|
||||||
// BME680 sensor on I2C bus
|
// BME680 sensor on I2C bus
|
||||||
@ -35,7 +41,11 @@
|
|||||||
//#define DISPLAY_FLIP 1 // use if display is rotated
|
//#define DISPLAY_FLIP 1 // use if display is rotated
|
||||||
|
|
||||||
// Settings for DCF77 interface
|
// Settings for DCF77 interface
|
||||||
#define HAS_DCF77 GPIO_NUM_13
|
//#define HAS_DCF77 GPIO_NUM_13
|
||||||
|
|
||||||
|
// Settings for IF482 interface
|
||||||
|
#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_12, GPIO_NUM_14 // IF482 serial port parameters
|
||||||
|
|
||||||
|
|
||||||
// user defined sensors (if connected)
|
// user defined sensors (if connected)
|
||||||
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
|
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
|
||||||
|
@ -20,12 +20,17 @@
|
|||||||
#define MY_OLED_SCL (22)
|
#define MY_OLED_SCL (22)
|
||||||
#define MY_OLED_RST U8X8_PIN_NONE
|
#define MY_OLED_RST U8X8_PIN_NONE
|
||||||
|
|
||||||
// Pins for on board DS3231 RTC chip
|
// Settings for on board DS3231 RTC chip
|
||||||
#define HAS_RTC MY_OLED_SDA, MY_OLED_SCL // SDA, SCL
|
#define HAS_RTC MY_OLED_SDA, MY_OLED_SCL // SDA, SCL
|
||||||
#define RTC_INT GPIO_NUM_34 // interrupt input from rtc
|
//#define RTC_INT GPIO_NUM_34 // timepulse with accuracy +/- 2*e-6 [microseconds] = 0,1728sec / day
|
||||||
|
//#define RTC_CLK (1000) // frequency of RTC clock signal in ms
|
||||||
|
|
||||||
// Settings for IF482 interface
|
// Settings for IF482 interface
|
||||||
#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_12, GPIO_NUM_14 // IF482 serial port parameters
|
//#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_12, GPIO_NUM_14 // IF482 serial port parameters
|
||||||
|
|
||||||
|
// Settings for DCF77 interface
|
||||||
|
#define HAS_DCF77 GPIO_NUM_14
|
||||||
|
#define DCF77_ACTIVE_LOW 1
|
||||||
|
|
||||||
// Settings for external GPS chip
|
// Settings for external GPS chip
|
||||||
#define HAS_GPS 1 // use on board GPS
|
#define HAS_GPS 1 // use on board GPS
|
||||||
|
@ -91,12 +91,16 @@ static const char TAG[] = "main";
|
|||||||
#define IF482_FRAME_SIZE (17)
|
#define IF482_FRAME_SIZE (17)
|
||||||
#define IF482_PULSE_DURATION (1000)
|
#define IF482_PULSE_DURATION (1000)
|
||||||
|
|
||||||
#ifdef RTC_CLK
|
// select internal / external clock
|
||||||
|
#if defined RTC_INT && defined RTC_CLK
|
||||||
#define PPS RTC_CLK
|
#define PPS RTC_CLK
|
||||||
|
#elif defined GPS_INT && defined GPS_CLK
|
||||||
|
#define PPS GPS_CLK
|
||||||
#else
|
#else
|
||||||
#define PPS IF482_PULSE_DURATION
|
#define PPS IF482_PULSE_DURATION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
HardwareSerial IF482(2); // use UART #2 (note: #1 may be in use for serial GPS)
|
HardwareSerial IF482(2); // use UART #2 (note: #1 may be in use for serial GPS)
|
||||||
|
|
||||||
// initialize and configure IF482 Generator
|
// initialize and configure IF482 Generator
|
||||||
@ -175,20 +179,22 @@ void if482_loop(void *pvParameters) {
|
|||||||
&wakeTime, // receives moment of call from isr
|
&wakeTime, // receives moment of call from isr
|
||||||
portMAX_DELAY); // wait forever (missing error handling here...)
|
portMAX_DELAY); // wait forever (missing error handling here...)
|
||||||
|
|
||||||
|
// select clock scale
|
||||||
#if (PPS == IF482_PULSE_DURATION) // we don't need clock rescaling
|
#if (PPS == IF482_PULSE_DURATION) // we don't need clock rescaling
|
||||||
// wait until it's time to start transmit telegram for next second
|
// wait until it's time to start transmit telegram for next second
|
||||||
vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot
|
vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot
|
||||||
IF482.print(IF482_Out(now() + 1));
|
IF482.print(IF482_Out(now() + 1));
|
||||||
|
|
||||||
#elif (PPS > IF482_PULSE_DURATION) // we need upclocking
|
#elif (PPS > IF482_PULSE_DURATION) // we need upclocking
|
||||||
for (uint8_t i = 1; i <= PPS / IF482_PULSE_DURATION; i++) {
|
for (uint8_t i = 1; i <= PPS / IF482_PULSE_DURATION; i++) {
|
||||||
vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot
|
vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot
|
||||||
IF482.print(IF482_Out(now() + 1));
|
IF482.print(IF482_Out(now() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif (PPS < IF482_PULSE_DURATION) // we need downclocking
|
#elif (PPS < IF482_PULSE_DURATION) // we need downclocking
|
||||||
IF482.print(IF482_Out(now() + 1));
|
IF482.print(IF482_Out(now() + 1));
|
||||||
vTaskDelayUntil(&wakeTime,
|
vTaskDelayUntil(&wakeTime,
|
||||||
shotTime - PPS); // sets waketime to moment of shot
|
shotTime - PPS); // sets waketime to moment of shot
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // if482_loop()
|
} // if482_loop()
|
||||||
|
@ -102,8 +102,10 @@ float get_rtctemp(void) {
|
|||||||
|
|
||||||
#endif // HAS_RTC
|
#endif // HAS_RTC
|
||||||
|
|
||||||
int pps_init(uint32_t clk_freq_ms) {
|
// helper function to setup a pulse for time synchronisation
|
||||||
// use fixed pulse clock as time base
|
int pps_init(uint32_t pulse_period_ms) {
|
||||||
|
|
||||||
|
// use pulse from on board RTC chip as time base with fixed frequency
|
||||||
#if defined RTC_INT && defined RTC_CLK
|
#if defined RTC_INT && defined RTC_CLK
|
||||||
|
|
||||||
// setup external interupt for active low RTC INT pin
|
// setup external interupt for active low RTC INT pin
|
||||||
@ -121,13 +123,16 @@ int pps_init(uint32_t clk_freq_ms) {
|
|||||||
}
|
}
|
||||||
return 1; // success
|
return 1; // success
|
||||||
|
|
||||||
|
#elif defined RTC_INT && defined HAS_GPS
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// use clock with adjustable frequency
|
// use ESP32 hardware timer as time base with adjustable frequency
|
||||||
if (clk_freq_ms) {
|
if (pulse_period_ms) {
|
||||||
ESP_LOGI(TAG, "Time base ESP32 clock");
|
ESP_LOGI(TAG, "Time base ESP32 clock");
|
||||||
clockCycle = timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec
|
clockCycle =
|
||||||
|
timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec
|
||||||
timerAttachInterrupt(clockCycle, &CLOCKIRQ, true);
|
timerAttachInterrupt(clockCycle, &CLOCKIRQ, true);
|
||||||
timerAlarmWrite(clockCycle, 10 * clk_freq_ms, true); //ms
|
timerAlarmWrite(clockCycle, 10 * pulse_period_ms, true); // ms
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "Invalid pulse clock frequency");
|
ESP_LOGE(TAG, "Invalid pulse clock frequency");
|
||||||
return 0; // failure
|
return 0; // failure
|
||||||
@ -138,7 +143,8 @@ int pps_init(uint32_t clk_freq_ms) {
|
|||||||
|
|
||||||
void pps_start() {
|
void pps_start() {
|
||||||
#ifdef RTC_INT // start external clock
|
#ifdef RTC_INT // start external clock
|
||||||
attachInterrupt(digitalPinToInterrupt(RTC_INT), CLOCKIRQ, FALLING);
|
//attachInterrupt(digitalPinToInterrupt(RTC_INT), CLOCKIRQ, FALLING);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(RTC_INT), CLOCKIRQ, RISING);
|
||||||
#else // start internal clock
|
#else // start internal clock
|
||||||
timerAlarmEnable(clockCycle);
|
timerAlarmEnable(clockCycle);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user