mirror of
https://github.com/manuelbl/ttn-esp32.git
synced 2025-07-17 16:12:52 +02:00
Convert hal_esp32 to C
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
*
|
||||
* ttn-esp32 - The Things Network device library for ESP-IDF / SX127x
|
||||
*
|
||||
* Copyright (c) 2018-2019 Manuel Bleichenbacher
|
||||
* Copyright (c) 2018-2021 Manuel Bleichenbacher
|
||||
*
|
||||
* Licensed under MIT License
|
||||
* https://opensource.org/licenses/MIT
|
||||
@ -10,85 +10,33 @@
|
||||
* Hardware abstraction layer to run LMIC on a ESP32 using ESP-IDF.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _hal_esp32_h_
|
||||
#define _hal_esp32_h_
|
||||
#ifndef HAL_ESP32_H
|
||||
#define HAL_ESP32_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/queue.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_master.h>
|
||||
#include <esp_timer.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "driver/spi_master.h"
|
||||
|
||||
|
||||
enum WaitKind {
|
||||
CHECK_IO,
|
||||
WAIT_FOR_ANY_EVENT,
|
||||
WAIT_FOR_TIMER
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
void hal_esp32_configure_pins(spi_host_device_t spi_host, uint8_t nss, uint8_t rxtx, uint8_t rst, uint8_t dio0, uint8_t dio1);
|
||||
void hal_esp32_start_lmic_task(void);
|
||||
void hal_esp32_stop_lmic_task(void);
|
||||
|
||||
class HAL_ESP32
|
||||
{
|
||||
public:
|
||||
HAL_ESP32();
|
||||
void hal_esp32_wake_up(void);
|
||||
void hal_esp32_init_critical_section(void);
|
||||
void hal_esp32_enter_critical_section(void);
|
||||
void hal_esp32_leave_critical_section(void);
|
||||
|
||||
void configurePins(spi_host_device_t spi_host, uint8_t nss, uint8_t rxtx, uint8_t rst, uint8_t dio0, uint8_t dio1);
|
||||
void init();
|
||||
void startLMICTask();
|
||||
void stopLMICTask();
|
||||
|
||||
void wakeUp();
|
||||
void initCriticalSection();
|
||||
void enterCriticalSection();
|
||||
void leaveCriticalSection();
|
||||
|
||||
void spiWrite(uint8_t cmd, const uint8_t *buf, size_t len);
|
||||
void spiRead(uint8_t cmd, uint8_t *buf, size_t len);
|
||||
uint8_t checkTimer(uint32_t osTime);
|
||||
void sleep();
|
||||
|
||||
uint32_t waitUntil(uint32_t osTime);
|
||||
|
||||
spi_host_device_t spiHost;
|
||||
gpio_num_t pinNSS;
|
||||
gpio_num_t pinRxTx;
|
||||
gpio_num_t pinRst;
|
||||
gpio_num_t pinDIO0;
|
||||
gpio_num_t pinDIO1;
|
||||
int8_t rssiCal;
|
||||
|
||||
private:
|
||||
static void lmicBackgroundTask(void* pvParameter);
|
||||
static void dioIrqHandler(void* arg);
|
||||
static void timerCallback(void *arg);
|
||||
static int64_t osTimeToEspTime(int64_t espNow, uint32_t osTime);
|
||||
|
||||
void ioInit();
|
||||
void spiInit();
|
||||
void timerInit();
|
||||
|
||||
void setNextAlarm(int64_t time);
|
||||
void armTimer(int64_t espNow);
|
||||
void disarmTimer();
|
||||
bool wait(WaitKind waitKind);
|
||||
|
||||
static TaskHandle_t lmicTask;
|
||||
static uint32_t dioInterruptTime;
|
||||
static uint8_t dioNum;
|
||||
|
||||
spi_device_handle_t spiHandle;
|
||||
spi_transaction_t spiTransaction;
|
||||
SemaphoreHandle_t mutex;
|
||||
esp_timer_handle_t timer;
|
||||
int64_t nextAlarm;
|
||||
volatile bool runBackgroundTask;
|
||||
};
|
||||
|
||||
extern HAL_ESP32 ttn_hal;
|
||||
void hal_esp32_set_rssi_cal(int8_t rssi_cal);
|
||||
|
||||
|
||||
#endif // _hal_esp32_h_
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // HAL_ESP32_H
|
||||
|
Reference in New Issue
Block a user