mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-29 03:58:43 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a3a92ffdb | |||
| 9ae6050feb | |||
| 5a956deb4b | |||
| b74b250db5 | |||
| ab4d01654b | |||
| 1a32b5be12 | |||
| 0f0fdf894c | |||
| 348b7724a3 | |||
| d5ade3299f | |||
| 5d914b5e34 | |||
| f8dd441827 |
@@ -0,0 +1,3 @@
|
||||
[submodule "espnet/esp-idf"]
|
||||
path = espnet/esp-idf
|
||||
url = https://github.com/espressif/esp-idf.git
|
||||
@@ -214,6 +214,6 @@ NOTESTS = build examples flash semihosting pcd8544 shiftregister st7789 micropho
|
||||
TESTS = $(filter-out $(addsuffix /%,$(NOTESTS)),$(DRIVERS))
|
||||
|
||||
unit-test:
|
||||
@go test -v . $(addprefix ./,$(TESTS))
|
||||
@go test -v $(addprefix ./,$(TESTS))
|
||||
|
||||
test: clean fmt-check unit-test smoke-test
|
||||
|
||||
+13
-2
@@ -60,8 +60,19 @@ func (d *Device) Connected() bool {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000)
|
||||
func (d *Device) ReadTemperature() (temperature drivers.Temperature, err error) {
|
||||
return (drivers.Temperature(d.readUint16(RegTempValueMSB)) * 1000) / 128, nil
|
||||
func (d *Device) ReadTemperature() (temperature int32, err error) {
|
||||
return (int32(d.readUint16(RegTempValueMSB)) * 1000) / 128, nil
|
||||
}
|
||||
|
||||
// ReadTempC returns the value in the temperature value register, in Celsius.
|
||||
func (d *Device) ReadTempC() float32 {
|
||||
t := d.readUint16(RegTempValueMSB)
|
||||
return float32(int(t)) / 128.0
|
||||
}
|
||||
|
||||
// ReadTempF returns the value in the temperature value register, in Fahrenheit.
|
||||
func (d *Device) ReadTempF() float32 {
|
||||
return d.ReadTempC()*1.8 + 32.0
|
||||
}
|
||||
|
||||
func (d *Device) writeByte(reg uint8, data byte) {
|
||||
|
||||
+2
-2
@@ -114,14 +114,14 @@ func (d *Device) Reset() {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000)
|
||||
func (d *Device) ReadTemperature() (drivers.Temperature, error) {
|
||||
func (d *Device) ReadTemperature() (int32, error) {
|
||||
data, err := d.readData()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
temp, _ := d.calculateTemp(data)
|
||||
return drivers.Temperature(temp), nil
|
||||
return temp, nil
|
||||
}
|
||||
|
||||
// ReadPressure returns the pressure in milli pascals mPa
|
||||
|
||||
+2
-2
@@ -81,7 +81,7 @@ func (d *DeviceSPI) Reset() error {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000).
|
||||
func (d *DeviceSPI) ReadTemperature() (temperature drivers.Temperature, err error) {
|
||||
func (d *DeviceSPI) ReadTemperature() (temperature int32, err error) {
|
||||
data := d.buf[:3]
|
||||
data[0] = 0x80 | reg_TEMPERATURE_0
|
||||
data[1] = 0
|
||||
@@ -109,7 +109,7 @@ func (d *DeviceSPI) ReadTemperature() (temperature drivers.Temperature, err erro
|
||||
// rawTemperature * 1000 * 64 / 0x8000 + 23000
|
||||
// rawTemperature * 64000 / 0x8000 + 23000
|
||||
// rawTemperature * 125 / 64 + 23000
|
||||
temperature = drivers.Temperature(rawTemperature)*125/64 + 23000
|
||||
temperature = int32(rawTemperature)*125/64 + 23000
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -81,14 +81,14 @@ func (d *Device) Configure() {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000).
|
||||
func (d *Device) ReadTemperature() (temperature drivers.Temperature, err error) {
|
||||
func (d *Device) ReadTemperature() (temperature int32, err error) {
|
||||
rawTemp, err := d.rawTemp()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
b5 := d.calculateB5(rawTemp)
|
||||
t := (b5 + 8) >> 4
|
||||
return drivers.Temperature(100 * t), nil
|
||||
return 100 * t, nil
|
||||
}
|
||||
|
||||
// ReadPressure returns the pressure in milli pascals (mPa).
|
||||
|
||||
+2
-2
@@ -132,7 +132,7 @@ func (d *Device) PrintCali() {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000).
|
||||
func (d *Device) ReadTemperature() (temperature drivers.Temperature, err error) {
|
||||
func (d *Device) ReadTemperature() (temperature int32, err error) {
|
||||
data, err := d.readData(REG_TEMP, 3)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -150,7 +150,7 @@ func (d *Device) ReadTemperature() (temperature drivers.Temperature, err error)
|
||||
|
||||
// Convert from degrees to milli degrees by multiplying by 10.
|
||||
// Will output 30250 milli degrees celsius for 30.25 degrees celsius
|
||||
temperature = drivers.Temperature(10 * ((tFine*5 + 128) >> 8))
|
||||
temperature = 10 * ((tFine*5 + 128) >> 8)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -133,16 +133,16 @@ func (d *Device) tlinCompensate() (int64, error) {
|
||||
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in milli degrees Celsius, i.e 24260 / 1000 = 24.26°C.
|
||||
func (d *Device) ReadTemperature() (drivers.Temperature, error) {
|
||||
// ReadTemperature returns the temperature in centicelsius, i.e 2426 / 100 = 24.26 C
|
||||
func (d *Device) ReadTemperature() (int32, error) {
|
||||
|
||||
tlin, err := d.tlinCompensate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
temp := (tlin * 125) / 8192
|
||||
return drivers.Temperature(temp), nil
|
||||
temp := (tlin * 25) / 16384
|
||||
return int32(temp), nil
|
||||
}
|
||||
|
||||
// ReadPressure returns the pressure in centipascals, i.e 10132520 / 100 = 101325.20 Pa
|
||||
|
||||
@@ -35,6 +35,18 @@ func (d DeviceType) extractData(buf []byte) (temp int16, hum uint16) {
|
||||
return
|
||||
}
|
||||
|
||||
// Celsius and Fahrenheit temperature scales
|
||||
type TemperatureScale uint8
|
||||
|
||||
func (t TemperatureScale) convertToFloat(temp int16) float32 {
|
||||
if t == C {
|
||||
return float32(temp) / 10
|
||||
} else {
|
||||
// Fahrenheit
|
||||
return float32(temp)*(9.0/50.) + 32.
|
||||
}
|
||||
}
|
||||
|
||||
// All functions return ErrorCode instance as error. This class can be used for more efficient error processing
|
||||
type ErrorCode uint8
|
||||
|
||||
@@ -45,6 +57,9 @@ const (
|
||||
DHT11 DeviceType = iota
|
||||
DHT22
|
||||
|
||||
C TemperatureScale = iota
|
||||
F
|
||||
|
||||
ChecksumError ErrorCode = iota
|
||||
NoSignalError
|
||||
NoDataError
|
||||
|
||||
+15
-6
@@ -9,15 +9,14 @@ package dht // import "tinygo.org/x/drivers/dht"
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
)
|
||||
|
||||
// DummyDevice provides a basic interface for DHT devices.
|
||||
type DummyDevice interface {
|
||||
ReadMeasurements() error
|
||||
Measurements() (temperature int16, humidity uint16, err error)
|
||||
Temperature() (drivers.Temperature, error)
|
||||
Temperature() (int16, error)
|
||||
TemperatureFloat(scale TemperatureScale) (float32, error)
|
||||
Humidity() (uint16, error)
|
||||
HumidityFloat() (float32, error)
|
||||
}
|
||||
@@ -50,13 +49,23 @@ func (t *device) ReadMeasurements() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Getter for temperature. The temperature is returned in milli degrees Celsius.
|
||||
// Getter for temperature. Temperature method returns temperature as it is sent by device.
|
||||
// The temperature is measured temperature in Celsius multiplied by 10.
|
||||
// If no successful measurements for this device was performed, returns UninitializedDataError.
|
||||
func (t *device) Temperature() (drivers.Temperature, error) {
|
||||
func (t *device) Temperature() (int16, error) {
|
||||
if !t.initialized {
|
||||
return 0, UninitializedDataError
|
||||
}
|
||||
return drivers.Temperature(t.temperature) * 100, nil
|
||||
return t.temperature, nil
|
||||
}
|
||||
|
||||
// Getter for temperature. TemperatureFloat returns temperature in a given scale.
|
||||
// If no successful measurements for this device was performed, returns UninitializedDataError.
|
||||
func (t *device) TemperatureFloat(scale TemperatureScale) (float32, error) {
|
||||
if !t.initialized {
|
||||
return 0, UninitializedDataError
|
||||
}
|
||||
return scale.convertToFloat(t.temperature), nil
|
||||
}
|
||||
|
||||
// Getter for humidity. Humidity returns humidity as it is sent by device.
|
||||
|
||||
@@ -9,8 +9,6 @@ package dht // import "tinygo.org/x/drivers/dht"
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
)
|
||||
|
||||
// Device interface provides main functionality of the DHTXX sensors.
|
||||
@@ -37,9 +35,10 @@ func (m *managedDevice) Measurements() (temperature int16, humidity uint16, err
|
||||
return m.t.Measurements()
|
||||
}
|
||||
|
||||
// Getter for temperature. The temperature is returned in milli degrees Celsius.
|
||||
// Getter for temperature. Temperature method returns temperature as it is sent by device.
|
||||
// The temperature is measured temperature in Celsius multiplied by 10.
|
||||
// Depending on the UpdatePolicy of the device may update cached measurements.
|
||||
func (m *managedDevice) Temperature() (temp drivers.Temperature, err error) {
|
||||
func (m *managedDevice) Temperature() (temp int16, err error) {
|
||||
err = m.checkForUpdateOnDataRequest()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -65,6 +64,16 @@ func (m *managedDevice) checkForUpdateOnDataRequest() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Getter for temperature. TemperatureFloat returns temperature in a given scale.
|
||||
// Depending on the UpdatePolicy of the device may update cached measurements.
|
||||
func (m *managedDevice) TemperatureFloat(scale TemperatureScale) (float32, error) {
|
||||
err := m.checkForUpdateOnDataRequest()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return m.t.TemperatureFloat(scale)
|
||||
}
|
||||
|
||||
// Getter for humidity. Humidity returns humidity as it is sent by device.
|
||||
// The humidity is measured in percentages multiplied by 10.
|
||||
// Depending on the UpdatePolicy of the device may update cached measurements.
|
||||
|
||||
+2
-2
@@ -134,13 +134,13 @@ func (d *Device) ReadTime() (dt time.Time, err error) {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in millicelsius (mC)
|
||||
func (d *Device) ReadTemperature() (drivers.Temperature, error) {
|
||||
func (d *Device) ReadTemperature() (int32, error) {
|
||||
data := make([]uint8, 2)
|
||||
err := d.bus.ReadRegister(uint8(d.Address), REG_TEMP, data)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return drivers.Temperature(int32(data[0])*1000 + int32((data[1]>>6)*25)*10), nil
|
||||
return int32(data[0])*1000 + int32((data[1]>>6)*25)*10, nil
|
||||
}
|
||||
|
||||
// uint8ToBCD converts a byte to BCD for the DS3231
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package espnet
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -DCONFIG_IDF_TARGET_ESP32C3
|
||||
#cgo CFLAGS: -Iinclude
|
||||
#cgo CFLAGS: -Iesp-idf/components/esp_common/include
|
||||
#cgo CFLAGS: -Iesp-idf/components/esp_event/include
|
||||
#cgo CFLAGS: -Iesp-idf/components/esp_netif/include
|
||||
#cgo CFLAGS: -Iesp-idf/components/esp_wifi/include
|
||||
|
||||
#cgo LDFLAGS: -Lesp-idf/components/esp_wifi/lib/esp32c3 -lnet80211 -lpp -lphy -lmesh -lcore
|
||||
#cgo LDFLAGS: -Tesp-idf/components/esp_rom/esp32c3/ld/esp32c3.rom.ld
|
||||
|
||||
#include "esp_private/wifi.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "espnet.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import _ "compat/freertos"
|
||||
|
||||
type ESPWiFi struct {
|
||||
}
|
||||
|
||||
var WiFi = &ESPWiFi{}
|
||||
|
||||
type Config struct {
|
||||
}
|
||||
|
||||
var internalConfig = C.wifi_init_config_t{
|
||||
osi_funcs: &C.g_wifi_osi_funcs,
|
||||
wpa_crypto_funcs: C.g_wifi_default_wpa_crypto_funcs,
|
||||
static_rx_buf_num: 10,
|
||||
static_tx_buf_num: 10,
|
||||
mgmt_sbuf_num: 6,
|
||||
sta_disconnected_pm: true,
|
||||
magic: C.WIFI_INIT_CONFIG_MAGIC,
|
||||
}
|
||||
|
||||
func (wifi ESPWiFi) Configure(config Config) error {
|
||||
C.esp_wifi_internal_set_log_level(5)
|
||||
return makeError(C.esp_wifi_init_internal(&internalConfig))
|
||||
}
|
||||
|
||||
func (wifi ESPWiFi) AccessPointMAC() ([6]byte, error) {
|
||||
var mac [6]byte
|
||||
errCode := C.esp_wifi_get_mac(C.ESP_IF_WIFI_AP, &mac[0])
|
||||
return mac, makeError(errCode)
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
package espnet
|
||||
|
||||
// #include <esp_err.h>
|
||||
// #include <esp_wifi.h>
|
||||
import "C"
|
||||
|
||||
// Wrapper for C.esp_err_t. Don't convert a C.esp_err_t to an Error type,
|
||||
// instead use makeError to handle ESP_OK.
|
||||
type Error C.esp_err_t
|
||||
|
||||
// makeError converts a C.esp_err_t into an error or nil depending on whether
|
||||
// errCode indicates an error or not.
|
||||
func makeError(errCode C.esp_err_t) error {
|
||||
if errCode == C.ESP_OK {
|
||||
return nil
|
||||
}
|
||||
return Error(errCode)
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
switch {
|
||||
case e < C.ESP_ERR_WIFI_BASE:
|
||||
// esp-idf/components/esp_common/include/esp_err.h
|
||||
switch e {
|
||||
case C.ESP_OK:
|
||||
return "OK" // not an error
|
||||
case C.ESP_FAIL:
|
||||
return "ESP FAIL"
|
||||
case C.ESP_ERR_NO_MEM:
|
||||
return "Out of memory"
|
||||
case C.ESP_ERR_INVALID_ARG:
|
||||
return "Invalid argument"
|
||||
case C.ESP_ERR_INVALID_STATE:
|
||||
return "Invalid state"
|
||||
case C.ESP_ERR_INVALID_SIZE:
|
||||
return "Invalid size"
|
||||
case C.ESP_ERR_NOT_FOUND:
|
||||
return "Requested resource not found"
|
||||
case C.ESP_ERR_NOT_SUPPORTED:
|
||||
return "Operation or feature not supported"
|
||||
case C.ESP_ERR_TIMEOUT:
|
||||
return "Operation timed out"
|
||||
case C.ESP_ERR_INVALID_RESPONSE:
|
||||
return "Received response was invalid"
|
||||
case C.ESP_ERR_INVALID_CRC:
|
||||
return "CRC or checksum was invalid"
|
||||
case C.ESP_ERR_INVALID_VERSION:
|
||||
return "Version was invalid"
|
||||
case C.ESP_ERR_INVALID_MAC:
|
||||
return "MAC address was invalid"
|
||||
default:
|
||||
return "Unknown error"
|
||||
}
|
||||
case e >= C.ESP_ERR_WIFI_BASE && e < C.ESP_ERR_MESH_BASE:
|
||||
// esp-idf/components/esp_wifi/include/esp_wifi.h
|
||||
switch e {
|
||||
case C.ESP_ERR_WIFI_NOT_INIT:
|
||||
return "WiFi driver was not installed by esp_wifi_init"
|
||||
case C.ESP_ERR_WIFI_NOT_STARTED:
|
||||
return "WiFi driver was not started by esp_wifi_start"
|
||||
case C.ESP_ERR_WIFI_NOT_STOPPED:
|
||||
return "WiFi driver was not stopped by esp_wifi_stop"
|
||||
case C.ESP_ERR_WIFI_IF:
|
||||
return "WiFi interface error"
|
||||
case C.ESP_ERR_WIFI_MODE:
|
||||
return "WiFi mode error"
|
||||
case C.ESP_ERR_WIFI_STATE:
|
||||
return "WiFi internal state error"
|
||||
case C.ESP_ERR_WIFI_CONN:
|
||||
return "WiFi internal control block of station or soft-AP error"
|
||||
case C.ESP_ERR_WIFI_NVS:
|
||||
return "WiFi internal NVS module error"
|
||||
case C.ESP_ERR_WIFI_MAC:
|
||||
return "MAC address is invalid"
|
||||
case C.ESP_ERR_WIFI_SSID:
|
||||
return " SSID is invalid"
|
||||
case C.ESP_ERR_WIFI_PASSWORD:
|
||||
return "Password is invalid"
|
||||
case C.ESP_ERR_WIFI_TIMEOUT:
|
||||
return "Timeout error"
|
||||
case C.ESP_ERR_WIFI_WAKE_FAIL:
|
||||
return "WiFi is in sleep state(RF closed) and wakeup fail"
|
||||
case C.ESP_ERR_WIFI_WOULD_BLOCK:
|
||||
return "The caller would block"
|
||||
case C.ESP_ERR_WIFI_NOT_CONNECT:
|
||||
return "Station still in disconnect status"
|
||||
case C.ESP_ERR_WIFI_POST:
|
||||
return "Failed to post the event to WiFi task"
|
||||
case C.ESP_ERR_WIFI_INIT_STATE:
|
||||
return "Invalid WiFi state when init/deinit is called"
|
||||
case C.ESP_ERR_WIFI_STOP_STATE:
|
||||
return "Returned when WiFi is stopping"
|
||||
case C.ESP_ERR_WIFI_NOT_ASSOC:
|
||||
return "The WiFi connection is not associated"
|
||||
case C.ESP_ERR_WIFI_TX_DISALLOW:
|
||||
return "The WiFi TX is disallowed"
|
||||
default:
|
||||
return "Other WiFi error"
|
||||
}
|
||||
default:
|
||||
return "Other error"
|
||||
}
|
||||
}
|
||||
Submodule
+1
Submodule espnet/esp-idf added at c9646ff0be
+829
@@ -0,0 +1,829 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "espnet.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_private/wifi.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
|
||||
// Stub functions, to know which functions need to be implemented for OS
|
||||
// functionality.
|
||||
|
||||
static bool _env_is_chip(void) {
|
||||
printf("called: _env_is_chip\n");
|
||||
return false;
|
||||
}
|
||||
static void _set_intr(int32_t cpu_no, uint32_t intr_source, uint32_t intr_num, int32_t intr_prio) {
|
||||
printf("called: _set_intr\n");
|
||||
}
|
||||
static void _clear_intr(uint32_t intr_source, uint32_t intr_num) {
|
||||
printf("called: _clear_intr\n");
|
||||
}
|
||||
static void _set_isr(int32_t n, void *f, void *arg) {
|
||||
printf("called: _set_isr\n");
|
||||
}
|
||||
static void _ints_on(uint32_t mask) {
|
||||
printf("called: _ints_on\n");
|
||||
}
|
||||
static void _ints_off(uint32_t mask) {
|
||||
printf("called: _ints_off\n");
|
||||
}
|
||||
static bool _is_from_isr(void) {
|
||||
printf("called: _is_from_isr\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Having conflict between when include
|
||||
// #include "freertos/portmacro.h"
|
||||
|
||||
typedef struct {
|
||||
/* owner field values:
|
||||
* 0 - Uninitialized (invalid)
|
||||
* portMUX_FREE_VAL - Mux is free, can be locked by either CPU
|
||||
* CORE_ID_REGVAL_PRO / CORE_ID_REGVAL_APP - Mux is locked to the particular core
|
||||
*
|
||||
*
|
||||
* Any value other than portMUX_FREE_VAL, CORE_ID_REGVAL_PRO, CORE_ID_REGVAL_APP indicates corruption
|
||||
*/
|
||||
uint32_t owner;
|
||||
/* count field:
|
||||
* If mux is unlocked, count should be zero.
|
||||
* If mux is locked, count is non-zero & represents the number of recursive locks on the mux.
|
||||
*/
|
||||
uint32_t count;
|
||||
} portMUX_TYPE;
|
||||
|
||||
#define portMUX_FREE_VAL SPINLOCK_FREE
|
||||
#define SPINLOCK_FREE 0xB33FFFFF
|
||||
|
||||
#define portMUX_INITIALIZER_UNLOCKED { \
|
||||
.owner = portMUX_FREE_VAL, \
|
||||
.count = 0, \
|
||||
}
|
||||
|
||||
static void * _spin_lock_create(void) {
|
||||
portMUX_TYPE tmp = portMUX_INITIALIZER_UNLOCKED;
|
||||
void *mux = malloc(sizeof(portMUX_TYPE));
|
||||
if (mux) {
|
||||
memcpy(mux,&tmp,sizeof(portMUX_TYPE));
|
||||
return mux;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static void _spin_lock_delete(void *lock) {
|
||||
free(lock);
|
||||
}
|
||||
static uint32_t _wifi_int_disable(void *wifi_int_mux) {
|
||||
printf("called: _wifi_int_disable\n");
|
||||
return 0;
|
||||
}
|
||||
static void _wifi_int_restore(void *wifi_int_mux, uint32_t tmp) {
|
||||
printf("called: _wifi_int_restore\n");
|
||||
}
|
||||
static void _task_yield_from_isr(void) {
|
||||
printf("called: _task_yield_from_isr\n");
|
||||
}
|
||||
static void *_semphr_create(uint32_t max, uint32_t init) {
|
||||
return (void *)xSemaphoreCreateCounting(max, init);
|
||||
}
|
||||
static void _semphr_delete(void *semphr) {
|
||||
vSemaphoreDelete(semphr);
|
||||
}
|
||||
static int32_t _semphr_take(void *semphr, uint32_t block_time_tick) {
|
||||
if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
|
||||
return (int32_t)xSemaphoreTake(semphr, portMAX_DELAY);
|
||||
} else {
|
||||
return (int32_t)xSemaphoreTake(semphr, block_time_tick);
|
||||
}
|
||||
}
|
||||
static int32_t _semphr_give(void *semphr) {
|
||||
return (int32_t)xSemaphoreGive(semphr);
|
||||
}
|
||||
static void *_wifi_thread_semphr_get(void) {
|
||||
static SemaphoreHandle_t sem = NULL;
|
||||
if (!sem) {
|
||||
sem = xSemaphoreCreateCounting(1, 0);
|
||||
}
|
||||
return (void*)sem;
|
||||
}
|
||||
static void *_mutex_create(void) {
|
||||
printf("called: _mutex_create\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *_recursive_mutex_create(void) {
|
||||
return xSemaphoreCreateRecursiveMutex();
|
||||
}
|
||||
static void _mutex_delete(void *mutex) {
|
||||
return vSemaphoreDelete(mutex);
|
||||
}
|
||||
static int32_t _mutex_lock(void *mutex) {
|
||||
return (int32_t)xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
}
|
||||
static int32_t _mutex_unlock(void *mutex) {
|
||||
return (int32_t)xSemaphoreGiveRecursive(mutex);
|
||||
}
|
||||
static void * _queue_create(uint32_t queue_len, uint32_t item_size) {
|
||||
printf("called: _queue_create\n");
|
||||
return NULL;
|
||||
}
|
||||
static void _queue_delete(void *queue) {
|
||||
printf("called: _queue_delete\n");
|
||||
}
|
||||
static int32_t _queue_send(void *queue, void *item, uint32_t block_time_tick) {
|
||||
if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
|
||||
return (int32_t)xQueueSend(queue, item, portMAX_DELAY);
|
||||
} else {
|
||||
return (int32_t)xQueueSend(queue, item, block_time_tick);
|
||||
}
|
||||
}
|
||||
static int32_t _queue_send_from_isr(void *queue, void *item, void *hptw) {
|
||||
printf("called: _queue_send_from_isr\n");
|
||||
return 0;
|
||||
}
|
||||
static int32_t _queue_send_to_back(void *queue, void *item, uint32_t block_time_tick) {
|
||||
printf("called: _queue_send_to_back\n");
|
||||
return 0;
|
||||
}
|
||||
static int32_t _queue_send_to_front(void *queue, void *item, uint32_t block_time_tick) {
|
||||
printf("called: _queue_send_to_front\n");
|
||||
return 0;
|
||||
}
|
||||
static int32_t _queue_recv(void *queue, void *item, uint32_t block_time_tick) {
|
||||
if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
|
||||
return (int32_t)xQueueReceive(queue, item, portMAX_DELAY);
|
||||
} else {
|
||||
return (int32_t)xQueueReceive(queue, item, block_time_tick);
|
||||
}
|
||||
}
|
||||
static void * _event_group_create(void) {
|
||||
printf("called: _event_group_create\n");
|
||||
return NULL;
|
||||
}
|
||||
static void _event_group_delete(void *event) {
|
||||
printf("called: _event_group_delete\n");
|
||||
}
|
||||
static uint32_t _event_group_set_bits(void *event, uint32_t bits) {
|
||||
printf("called: _event_group_set_bits\n");
|
||||
return 0;
|
||||
}
|
||||
static uint32_t _event_group_clear_bits(void *event, uint32_t bits) {
|
||||
printf("called: _event_group_clear_bits\n");
|
||||
return 0;
|
||||
}
|
||||
static uint32_t _event_group_wait_bits(void *event, uint32_t bits_to_wait_for, int clear_on_exit, int wait_for_all_bits, uint32_t block_time_tick) {
|
||||
printf("called: _event_group_wait_bits\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define P(x) printf("called: "#x"\n");
|
||||
|
||||
static int32_t _task_create_pinned_to_core(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id) {
|
||||
// Note: using xTaskCreate instead of xTaskCreatePinnedToCore.
|
||||
return (uint32_t)xTaskCreate(task_func, name, stack_depth, param, prio, task_handle);
|
||||
}
|
||||
static int32_t _task_create(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle) {
|
||||
P(_task_create)
|
||||
return 0;
|
||||
}
|
||||
static void _task_delete(void *task_handle) {
|
||||
P(_task_delete)
|
||||
}
|
||||
static int32_t _task_ms_to_tick(uint32_t ms) {
|
||||
return (int32_t)(ms / portTICK_PERIOD_MS);
|
||||
}
|
||||
static int32_t _task_get_max_priority() {
|
||||
return configMAX_PRIORITIES;
|
||||
}
|
||||
static int32_t _event_post(const char* event_base, int32_t event_id, void* event_data, size_t event_data_size, uint32_t ticks_to_wait) {
|
||||
P(_event_post)
|
||||
return 0;
|
||||
}
|
||||
static uint32_t _get_free_heap_size(void) {
|
||||
P(_get_free_heap_size)
|
||||
return 0;
|
||||
}
|
||||
static uint32_t _rand(void) {
|
||||
P(_rand)
|
||||
return 0;
|
||||
}
|
||||
static void _dport_access_stall_other_cpu_start_wrap(void) {
|
||||
P(_dport_access_stall_other_cpu_start_wrap)
|
||||
}
|
||||
static void _dport_access_stall_other_cpu_end_wrap(void) {
|
||||
P(_dport_access_stall_other_cpu_end_wrap)
|
||||
}
|
||||
static void _wifi_apb80m_request(void) {
|
||||
P(_wifi_apb80m_request)
|
||||
}
|
||||
static void _wifi_apb80m_release(void) {
|
||||
P(_wifi_apb80m_release)
|
||||
}
|
||||
static void _phy_disable(void) {
|
||||
P(_phy_disable)
|
||||
}
|
||||
static void _phy_enable(void) {
|
||||
P(_phy_enable)
|
||||
}
|
||||
static int _phy_update_country_info(const char* country) {
|
||||
P(_phy_update_country_info)
|
||||
return 0;
|
||||
}
|
||||
static int _read_mac(uint8_t* mac, uint32_t type) {
|
||||
P(_read_mac)
|
||||
return 0;
|
||||
}
|
||||
static void _timer_arm(void *timer, uint32_t tmout, bool repeat) {
|
||||
P(_timer_arm)
|
||||
}
|
||||
static void _timer_disarm(void *timer) {
|
||||
P(_timer_disarm)
|
||||
}
|
||||
static void _timer_done(void *ptimer) {
|
||||
P(_timer_done)
|
||||
}
|
||||
static void _timer_setfn(void *ptimer, void *pfunction, void *parg) {
|
||||
P(_timer_setfn)
|
||||
}
|
||||
static void _timer_arm_us(void *ptimer, uint32_t us, bool repeat) {
|
||||
P(_timer_arm_us)
|
||||
}
|
||||
static void _wifi_reset_mac(void) {
|
||||
P(_wifi_reset_mac)
|
||||
}
|
||||
static void _wifi_clock_enable(void) {
|
||||
P(_wifi_clock_enable)
|
||||
}
|
||||
static void _wifi_clock_disable(void) {
|
||||
P(_wifi_clock_disable)
|
||||
}
|
||||
static void _wifi_rtc_enable_iso(void) {
|
||||
P(_wifi_rtc_enable_iso)
|
||||
}
|
||||
static void _wifi_rtc_disable_iso(void) {
|
||||
P(_wifi_rtc_disable_iso)
|
||||
}
|
||||
static int64_t _esp_timer_get_time(void) {
|
||||
P(_esp_timer_get_time)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_set_i8(uint32_t handle, const char* key, int8_t value) {
|
||||
P(_nvs_set_i8)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_get_i8(uint32_t handle, const char* key, int8_t* out_value) {
|
||||
P(_nvs_get_i8)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_set_u8(uint32_t handle, const char* key, uint8_t value) {
|
||||
P(_nvs_set_u8)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_get_u8(uint32_t handle, const char* key, uint8_t* out_value) {
|
||||
P(_nvs_get_u8)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_set_u16(uint32_t handle, const char* key, uint16_t value) {
|
||||
P(_nvs_set_u16)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_get_u16(uint32_t handle, const char* key, uint16_t* out_value) {
|
||||
P(_nvs_get_u16)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_open(const char* name, uint32_t open_mode, uint32_t *out_handle) {
|
||||
P(_nvs_open)
|
||||
return 0;
|
||||
}
|
||||
static void _nvs_close(uint32_t handle) {
|
||||
P(_nvs_close)
|
||||
}
|
||||
static int _nvs_commit(uint32_t handle) {
|
||||
P(_nvs_commit)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_set_blob(uint32_t handle, const char* key, const void* value, size_t length) {
|
||||
P(_nvs_set_blob)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_get_blob(uint32_t handle, const char* key, void* out_value, size_t* length) {
|
||||
P(_nvs_get_blob)
|
||||
return 0;
|
||||
}
|
||||
static int _nvs_erase_key(uint32_t handle, const char* key) {
|
||||
P(_nvs_erase_key)
|
||||
return 0;
|
||||
}
|
||||
static int _get_random(uint8_t *buf, size_t len) {
|
||||
P(_get_random)
|
||||
return 0;
|
||||
}
|
||||
static int _get_time(void *t) {
|
||||
P(_get_time)
|
||||
return 0;
|
||||
}
|
||||
static unsigned long _random(void) {
|
||||
P(_random)
|
||||
return 0;
|
||||
}
|
||||
// #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
|
||||
// uint32_t (* _slowclk_cal_get(void)
|
||||
// #endif
|
||||
static void _log_write(uint32_t level, const char* tag, const char* format, ...) {
|
||||
va_list argList;
|
||||
printf("[%s] ", tag);
|
||||
va_start(argList, format);
|
||||
vprintf(format, argList);
|
||||
va_end(argList);
|
||||
printf("\n");
|
||||
}
|
||||
static void _log_writev(uint32_t level, const char* tag, const char* format, va_list args) {
|
||||
printf("[%s] ", tag);
|
||||
vprintf(format, args);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static uint32_t _log_timestamp(void) {
|
||||
P(_log_timestamp)
|
||||
return 0;
|
||||
}
|
||||
static void* _malloc_internal(size_t size) {
|
||||
printf("called: _malloc_internal(%d)\n", size);
|
||||
return malloc(size);
|
||||
}
|
||||
static void* _realloc_internal(void *ptr, size_t size) {
|
||||
printf("called: _realloc_internal(%p,%d)\n", ptr, size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void* _calloc_internal(size_t n, size_t size) {
|
||||
printf("called: _calloc_internal(%d,%d)\n", n, size);
|
||||
return malloc(n * size);
|
||||
}
|
||||
static void* _zalloc_internal(size_t size) {
|
||||
printf("called: _zalloc_internal(%d)\n", size);
|
||||
return NULL;
|
||||
}
|
||||
static void* _wifi_malloc(size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
static void* _wifi_realloc(void *ptr, size_t size) {
|
||||
printf("called: _wifi_realloc(%d)\n", size);
|
||||
return NULL;
|
||||
}
|
||||
static void* _wifi_calloc(size_t n, size_t size) {
|
||||
return calloc(n, size);
|
||||
}
|
||||
static void* _wifi_zalloc(size_t size) {
|
||||
return calloc(1, size);
|
||||
}
|
||||
static void* _wifi_create_queue(int queue_len, int item_size) {
|
||||
wifi_static_queue_t *queue = (wifi_static_queue_t*)malloc(sizeof(wifi_static_queue_t));
|
||||
queue->handle = xQueueCreate( queue_len, item_size);
|
||||
return queue;
|
||||
}
|
||||
static void _wifi_delete_queue(void * queue) {
|
||||
vQueueDelete(queue);
|
||||
}
|
||||
static int _coex_init(void) {
|
||||
P(_coex_init)
|
||||
return 0;
|
||||
}
|
||||
static void _coex_deinit(void) {
|
||||
P(_coex_deinit)
|
||||
}
|
||||
static int _coex_enable(void) {
|
||||
P(_coex_enable)
|
||||
return 0;
|
||||
}
|
||||
static void _coex_disable(void) {
|
||||
P(_coex_disable)
|
||||
}
|
||||
static uint32_t _coex_status_get(void) {
|
||||
P(_coex_status_get)
|
||||
return 0;
|
||||
}
|
||||
static void _coex_condition_set(uint32_t type, bool dissatisfy) {
|
||||
P(_coex_condition_set)
|
||||
}
|
||||
static int _coex_wifi_request(uint32_t event, uint32_t latency, uint32_t duration) {
|
||||
P(_coex_wifi_request)
|
||||
return 0;
|
||||
}
|
||||
static int _coex_wifi_release(uint32_t event) {
|
||||
P(_coex_wifi_release)
|
||||
return 0;
|
||||
}
|
||||
static int _coex_wifi_channel_set(uint8_t primary, uint8_t secondary) {
|
||||
P(_coex_wifi_channel_set)
|
||||
return 0;
|
||||
}
|
||||
static int _coex_event_duration_get(uint32_t event, uint32_t *duration) {
|
||||
P(_coex_event_duration_get)
|
||||
return 0;
|
||||
}
|
||||
static int _coex_pti_get(uint32_t event, uint8_t *pti) {
|
||||
P(_coex_pti_get)
|
||||
return 0;
|
||||
}
|
||||
static void _coex_schm_status_bit_clear(uint32_t type, uint32_t status) {
|
||||
P(_coex_schm_status_bit_clear)
|
||||
}
|
||||
static void _coex_schm_status_bit_set(uint32_t type, uint32_t status) {
|
||||
P(_coex_schm_status_bit_set)
|
||||
}
|
||||
static int _coex_schm_interval_set(uint32_t interval) {
|
||||
P(_coex_schm_interval_set)
|
||||
return 0;
|
||||
}
|
||||
static uint32_t _coex_schm_interval_get(void) {
|
||||
P(_coex_schm_interval_get)
|
||||
return 0;
|
||||
}
|
||||
static uint8_t _coex_schm_curr_period_get(void) {
|
||||
P(_coex_schm_curr_period_get)
|
||||
return 0;
|
||||
}
|
||||
static void* _coex_schm_curr_phase_get(void) {
|
||||
P(_coex_schm_curr_phase_get)
|
||||
return NULL;
|
||||
}
|
||||
static int _coex_schm_curr_phase_idx_set(int idx) {
|
||||
P(_coex_schm_curr_phase_idx_set)
|
||||
return 0;
|
||||
}
|
||||
static int _coex_schm_curr_phase_idx_get(void) {
|
||||
P(_coex_schm_curr_phase_idx_get)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint32_t _slowclk_cal_get(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// OS adapter functions.
|
||||
// See: esp-idf/components/esp_wifi/include/esp_private/wifi_os_adapter.h
|
||||
wifi_osi_funcs_t g_wifi_osi_funcs = {
|
||||
._version = ESP_WIFI_OS_ADAPTER_VERSION,
|
||||
._env_is_chip = _env_is_chip,
|
||||
._set_intr = _set_intr,
|
||||
._clear_intr = _clear_intr,
|
||||
._set_isr = _set_isr,
|
||||
._ints_on = _ints_on,
|
||||
._ints_off = _ints_off,
|
||||
._is_from_isr = _is_from_isr,
|
||||
._spin_lock_create = _spin_lock_create,
|
||||
._spin_lock_delete = _spin_lock_delete,
|
||||
._wifi_int_disable = _wifi_int_disable,
|
||||
._wifi_int_restore = _wifi_int_restore,
|
||||
._task_yield_from_isr = _task_yield_from_isr,
|
||||
._semphr_create = _semphr_create,
|
||||
._semphr_delete = _semphr_delete,
|
||||
._semphr_take = _semphr_take,
|
||||
._semphr_give = _semphr_give,
|
||||
._wifi_thread_semphr_get = _wifi_thread_semphr_get,
|
||||
._mutex_create = _mutex_create,
|
||||
._recursive_mutex_create = _recursive_mutex_create,
|
||||
._mutex_delete = _mutex_delete,
|
||||
._mutex_lock = _mutex_lock,
|
||||
._mutex_unlock = _mutex_unlock,
|
||||
._queue_create = _queue_create,
|
||||
._queue_delete = _queue_delete,
|
||||
._queue_send = _queue_send,
|
||||
._queue_send_from_isr = _queue_send_from_isr,
|
||||
._queue_send_to_back = _queue_send_to_back,
|
||||
._queue_send_to_front = _queue_send_to_front,
|
||||
._queue_recv = _queue_recv,
|
||||
._queue_msg_waiting = (uint32_t(*)(void *))uxQueueMessagesWaiting,
|
||||
._event_group_create = _event_group_create,
|
||||
._event_group_delete = _event_group_delete,
|
||||
._event_group_set_bits = _event_group_set_bits,
|
||||
._event_group_clear_bits = _event_group_clear_bits,
|
||||
._event_group_wait_bits = _event_group_wait_bits,
|
||||
._task_create_pinned_to_core = _task_create_pinned_to_core,
|
||||
._task_create = _task_create,
|
||||
._task_delete = _task_delete,
|
||||
._task_delay = vTaskDelay,
|
||||
._task_ms_to_tick = _task_ms_to_tick,
|
||||
._task_get_current_task = (void *(*)(void))xTaskGetCurrentTaskHandle,
|
||||
._task_get_max_priority = _task_get_max_priority,
|
||||
._malloc = malloc,
|
||||
._free = free,
|
||||
._event_post = _event_post,
|
||||
._get_free_heap_size = _get_free_heap_size,
|
||||
._rand = _rand,
|
||||
._dport_access_stall_other_cpu_start_wrap = _dport_access_stall_other_cpu_start_wrap,
|
||||
._dport_access_stall_other_cpu_end_wrap = _dport_access_stall_other_cpu_end_wrap,
|
||||
._wifi_apb80m_request = _wifi_apb80m_request,
|
||||
._wifi_apb80m_release = _wifi_apb80m_release,
|
||||
._phy_disable = _phy_disable,
|
||||
._phy_enable = _phy_enable,
|
||||
._phy_update_country_info = _phy_update_country_info,
|
||||
._read_mac = _read_mac,
|
||||
._timer_arm = _timer_arm,
|
||||
._timer_disarm = _timer_disarm,
|
||||
._timer_done = _timer_done,
|
||||
._timer_setfn = _timer_setfn,
|
||||
._timer_arm_us = _timer_arm_us,
|
||||
._wifi_reset_mac = _wifi_reset_mac,
|
||||
._wifi_clock_enable = _wifi_clock_enable,
|
||||
._wifi_clock_disable = _wifi_clock_disable,
|
||||
._wifi_rtc_enable_iso = _wifi_rtc_enable_iso,
|
||||
._wifi_rtc_disable_iso = _wifi_rtc_disable_iso,
|
||||
._esp_timer_get_time = _esp_timer_get_time,
|
||||
._nvs_set_i8 = _nvs_set_i8,
|
||||
._nvs_get_i8 = _nvs_get_i8,
|
||||
._nvs_set_u8 = _nvs_set_u8,
|
||||
._nvs_get_u8 = _nvs_get_u8,
|
||||
._nvs_set_u16 = _nvs_set_u16,
|
||||
._nvs_get_u16 = _nvs_get_u16,
|
||||
._nvs_open = _nvs_open,
|
||||
._nvs_close = _nvs_close,
|
||||
._nvs_commit = _nvs_commit,
|
||||
._nvs_set_blob = _nvs_set_blob,
|
||||
._nvs_get_blob = _nvs_get_blob,
|
||||
._nvs_erase_key = _nvs_erase_key,
|
||||
._get_random = _get_random,
|
||||
._get_time = _get_time,
|
||||
._random = _random,
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
|
||||
._slowclk_cal_get = _slowclk_cal_get,
|
||||
#endif
|
||||
._log_write = _log_write,
|
||||
._log_writev = _log_writev,
|
||||
._log_timestamp = _log_timestamp,
|
||||
._malloc_internal = _malloc_internal,
|
||||
._realloc_internal = _realloc_internal,
|
||||
._calloc_internal = _calloc_internal,
|
||||
._zalloc_internal = _zalloc_internal,
|
||||
._wifi_malloc = _wifi_malloc,
|
||||
._wifi_realloc = _wifi_realloc,
|
||||
._wifi_calloc = _wifi_calloc,
|
||||
._wifi_zalloc = _wifi_zalloc,
|
||||
._wifi_create_queue = _wifi_create_queue,
|
||||
._wifi_delete_queue = _wifi_delete_queue,
|
||||
._coex_init = _coex_init,
|
||||
._coex_deinit = _coex_deinit,
|
||||
._coex_enable = _coex_enable,
|
||||
._coex_disable = _coex_disable,
|
||||
._coex_status_get = _coex_status_get,
|
||||
._coex_condition_set = _coex_condition_set,
|
||||
._coex_wifi_request = _coex_wifi_request,
|
||||
._coex_wifi_release = _coex_wifi_release,
|
||||
._coex_wifi_channel_set = _coex_wifi_channel_set,
|
||||
._coex_event_duration_get = _coex_event_duration_get,
|
||||
._coex_pti_get = _coex_pti_get,
|
||||
._coex_schm_status_bit_clear = _coex_schm_status_bit_clear,
|
||||
._coex_schm_status_bit_set = _coex_schm_status_bit_set,
|
||||
._coex_schm_interval_set = _coex_schm_interval_set,
|
||||
._coex_schm_interval_get = _coex_schm_interval_get,
|
||||
._coex_schm_curr_period_get = _coex_schm_curr_period_get,
|
||||
._coex_schm_curr_phase_get = _coex_schm_curr_phase_get,
|
||||
._coex_schm_curr_phase_idx_set = _coex_schm_curr_phase_idx_set,
|
||||
._coex_schm_curr_phase_idx_get = _coex_schm_curr_phase_idx_get,
|
||||
|
||||
._magic = ESP_WIFI_OS_ADAPTER_MAGIC,
|
||||
};
|
||||
|
||||
static int esp_aes_wrap(const unsigned char *kek, int n, const unsigned char *plain, unsigned char *cipher) {
|
||||
P(aes_wrap)
|
||||
return -1;
|
||||
}
|
||||
static int esp_aes_unwrap(const unsigned char *kek, int n, const unsigned char *cipher, unsigned char *plain) {
|
||||
P(aes_unwrap)
|
||||
return -1;
|
||||
}
|
||||
static int hmac_sha256_vector(const unsigned char *key, int key_len, int num_elem,
|
||||
const unsigned char *addr[], const int *len, unsigned char *mac) {
|
||||
return -1;
|
||||
}
|
||||
static int sha256_prf(const unsigned char *key, int key_len, const char *label,
|
||||
const unsigned char *data, int data_len, unsigned char *buf, int buf_len) {
|
||||
P(sha256_prf)
|
||||
return -1;
|
||||
}
|
||||
static int hmac_md5(const unsigned char *key, unsigned int key_len, const unsigned char *data,
|
||||
unsigned int data_len, unsigned char *mac) {
|
||||
P(hmac_md5)
|
||||
return -1;
|
||||
}
|
||||
static int hamc_md5_vector(const unsigned char *key, unsigned int key_len, unsigned int num_elem,
|
||||
const unsigned char *addr[], const unsigned int *len, unsigned char *mac) {
|
||||
P(hamc_md5_vector)
|
||||
return -1;
|
||||
}
|
||||
static int hmac_sha1(const unsigned char *key, unsigned int key_len, const unsigned char *data,
|
||||
unsigned int data_len, unsigned char *mac) {
|
||||
P(hmac_sha1)
|
||||
return -1;
|
||||
}
|
||||
static int hmac_sha1_vector(const unsigned char *key, unsigned int key_len, unsigned int num_elem,
|
||||
const unsigned char *addr[], const unsigned int *len, unsigned char *mac) {
|
||||
P(hmac_sha1_vector)
|
||||
return -1;
|
||||
}
|
||||
static int sha1_prf(const unsigned char *key, unsigned int key_len, const char *label,
|
||||
const unsigned char *data, unsigned int data_len, unsigned char *buf, unsigned int buf_len) {
|
||||
P(sha1_prf)
|
||||
return -1;
|
||||
}
|
||||
static int sha1_vector(unsigned int num_elem, const unsigned char *addr[], const unsigned int *len,
|
||||
unsigned char *mac) {
|
||||
P(sha1_vector)
|
||||
return -1;
|
||||
}
|
||||
static int pbkdf2_sha1(const char *passphrase, const char *ssid, unsigned int ssid_len,
|
||||
int iterations, unsigned char *buf, unsigned int buflen) {
|
||||
P(pbkdf2_sha1)
|
||||
return -1;
|
||||
}
|
||||
static int rc4_skip(const unsigned char *key, unsigned int keylen, unsigned int skip,
|
||||
unsigned char *data, unsigned int data_len) {
|
||||
P(rc4_skip)
|
||||
return -1;
|
||||
}
|
||||
static int md5_vector(unsigned int num_elem, const unsigned char *addr[], const unsigned int *len,
|
||||
unsigned char *mac) {
|
||||
P(md5_vector)
|
||||
return -1;
|
||||
}
|
||||
static void aes_encrypt(void *ctx, const unsigned char *plain, unsigned char *crypt) {
|
||||
P(aes_encrypt)
|
||||
}
|
||||
static void * aes_encrypt_init(const unsigned char *key, unsigned int len) {
|
||||
P(aes_encrypt_init)
|
||||
return NULL;
|
||||
}
|
||||
static void aes_encrypt_deinit(void *ctx) {
|
||||
P(aes_encrypt_deinit)
|
||||
}
|
||||
static void aes_decrypt(void *ctx, const unsigned char *crypt, unsigned char *plain) {
|
||||
P(aes_decrypt)
|
||||
}
|
||||
static void * aes_decrypt_init(const unsigned char *key, unsigned int len) {
|
||||
P(aes_decrypt_init)
|
||||
return NULL;
|
||||
}
|
||||
static void aes_decrypt_deinit(void *ctx) {
|
||||
P(aes_decrypt_deinit)
|
||||
}
|
||||
static int aes_128_decrypt(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len) {
|
||||
P(aes_128_decrypt)
|
||||
return -1;
|
||||
}
|
||||
static int omac1_aes_128(const uint8_t *key, const uint8_t *data, size_t data_len,
|
||||
uint8_t *mic) {
|
||||
P(omac1_aes_128)
|
||||
return -1;
|
||||
}
|
||||
static uint8_t * ccmp_decrypt(const uint8_t *tk, const uint8_t *ieee80211_hdr,
|
||||
const uint8_t *data, size_t data_len,
|
||||
size_t *decrypted_len, bool espnow_pkt) {
|
||||
P(ccmp_decrypt)
|
||||
return NULL;
|
||||
}
|
||||
static uint8_t * ccmp_encrypt(const uint8_t *tk, uint8_t *frame, size_t len, size_t hdrlen,
|
||||
uint8_t *pn, int keyid, size_t *encrypted_len) {
|
||||
P(ccmp_encrypt)
|
||||
return NULL;
|
||||
}
|
||||
static int hmac_md5_vector(const unsigned char *key, unsigned int key_len, unsigned int num_elem,
|
||||
const unsigned char *addr[], const unsigned int *len, unsigned char *mac) {
|
||||
P(hmac_md5_vector)
|
||||
return -1;
|
||||
}
|
||||
static void esp_aes_encrypt(void *ctx, const unsigned char *plain, unsigned char *crypt) {
|
||||
P(esp_aes_encrypt)
|
||||
}
|
||||
static void esp_aes_decrypt(void *ctx, const unsigned char *crypt, unsigned char *plain) {
|
||||
P(esp_aes_decrypt)
|
||||
}
|
||||
static int aes_128_cbc_encrypt(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len) {
|
||||
P(aes_128_cbc_encrypt)
|
||||
return -1;
|
||||
}
|
||||
static int aes_128_cbc_decrypt(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len) {
|
||||
P(aes_128_cbc_decrypt)
|
||||
return -1;
|
||||
}
|
||||
|
||||
const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = {
|
||||
.size = sizeof(wpa_crypto_funcs_t),
|
||||
.version = ESP_WIFI_CRYPTO_VERSION,
|
||||
.aes_wrap = (esp_aes_wrap_t)esp_aes_wrap,
|
||||
.aes_unwrap = (esp_aes_unwrap_t)esp_aes_unwrap,
|
||||
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)hmac_sha256_vector,
|
||||
.sha256_prf = (esp_sha256_prf_t)sha256_prf,
|
||||
.hmac_md5 = (esp_hmac_md5_t)hmac_md5,
|
||||
.hamc_md5_vector = (esp_hmac_md5_vector_t)hmac_md5_vector,
|
||||
.hmac_sha1 = (esp_hmac_sha1_t)hmac_sha1,
|
||||
.hmac_sha1_vector = (esp_hmac_sha1_vector_t)hmac_sha1_vector,
|
||||
.sha1_prf = (esp_sha1_prf_t)sha1_prf,
|
||||
.sha1_vector = (esp_sha1_vector_t)sha1_vector,
|
||||
.pbkdf2_sha1 = (esp_pbkdf2_sha1_t)pbkdf2_sha1,
|
||||
.rc4_skip = (esp_rc4_skip_t)rc4_skip,
|
||||
.md5_vector = (esp_md5_vector_t)md5_vector,
|
||||
.aes_encrypt = (esp_aes_encrypt_t)esp_aes_encrypt,
|
||||
.aes_encrypt_init = (esp_aes_encrypt_init_t)aes_encrypt_init,
|
||||
.aes_encrypt_deinit = (esp_aes_encrypt_deinit_t)aes_encrypt_deinit,
|
||||
.aes_decrypt = (esp_aes_decrypt_t)esp_aes_decrypt,
|
||||
.aes_decrypt_init = (esp_aes_decrypt_init_t)aes_decrypt_init,
|
||||
.aes_decrypt_deinit = (esp_aes_decrypt_deinit_t)aes_decrypt_deinit,
|
||||
.aes_128_encrypt = (esp_aes_128_encrypt_t)aes_128_cbc_encrypt,
|
||||
.aes_128_decrypt = (esp_aes_128_decrypt_t)aes_128_cbc_decrypt,
|
||||
.omac1_aes_128 = (esp_omac1_aes_128_t)omac1_aes_128,
|
||||
.ccmp_decrypt = (esp_ccmp_decrypt_t)ccmp_decrypt,
|
||||
.ccmp_encrypt = (esp_ccmp_encrypt_t)ccmp_encrypt
|
||||
};
|
||||
|
||||
// This is a string constant that is used all over ESP-IDF and is also used by
|
||||
// libnet80211.a. The main purpose is to be a fixed pointer that can be compared
|
||||
// against etc.
|
||||
const char *WIFI_EVENT = "WIFI_EVENT";
|
||||
|
||||
// Required by libphy.a
|
||||
int phy_printf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
printf("phy: ");
|
||||
int res = vprintf(format, args);
|
||||
va_end(args);
|
||||
return res;
|
||||
}
|
||||
|
||||
// Required by libpp.a
|
||||
int pp_printf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
printf("pp: ");
|
||||
int res = vprintf(format, args);
|
||||
va_end(args);
|
||||
return res;
|
||||
}
|
||||
|
||||
// Required by libnet80211.a
|
||||
int net80211_printf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
printf("net80211: ");
|
||||
int res = vprintf(format, args);
|
||||
va_end(args);
|
||||
return res;
|
||||
}
|
||||
|
||||
// Source: esp-idf/components/wpa_supplicant/src/utils/common.c
|
||||
static int hex2num(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F')
|
||||
return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Source: esp-idf/components/wpa_supplicant/src/utils/common.c
|
||||
int hex2byte(const char *hex)
|
||||
{
|
||||
int a, b;
|
||||
a = hex2num(*hex++);
|
||||
if (a < 0)
|
||||
return -1;
|
||||
b = hex2num(*hex++);
|
||||
if (b < 0)
|
||||
return -1;
|
||||
return (a << 4) | b;
|
||||
}
|
||||
|
||||
// Source: esp-idf/components/wpa_supplicant/src/utils/common.c
|
||||
/**
|
||||
* hexstr2bin - Convert ASCII hex string into binary data
|
||||
* @hex: ASCII hex string (e.g., "01ab")
|
||||
* @buf: Buffer for the binary data
|
||||
* @len: Length of the text to convert in bytes (of buf); hex will be double
|
||||
* this size
|
||||
* Returns: 0 on success, -1 on failure (invalid hex string)
|
||||
*/
|
||||
int hexstr2bin(const char *hex, uint8_t *buf, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
int a;
|
||||
const char *ipos = hex;
|
||||
uint8_t *opos = buf;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
a = hex2byte(ipos);
|
||||
if (a < 0)
|
||||
return -1;
|
||||
*opos++ = a;
|
||||
ipos += 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "esp_private/wifi_os_adapter.h"
|
||||
|
||||
extern wifi_osi_funcs_t g_wifi_osi_funcs;
|
||||
@@ -19,8 +19,8 @@ func main() {
|
||||
sensor.Configure()
|
||||
|
||||
for {
|
||||
temp, _ := sensor.ReadTemperature()
|
||||
fmt.Printf("temperature: %f°C\r\n", temp.Celsius())
|
||||
temp := sensor.ReadTempF()
|
||||
fmt.Printf("temperature: %f\r\n", temp)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ func main() {
|
||||
|
||||
for {
|
||||
temp, _ := sensor.ReadTemperature()
|
||||
println("Temperature:", strconv.FormatFloat(float64(temp.Celsius()), 'f', 2, 64), "°C")
|
||||
println("Temperature:", strconv.FormatFloat(float64(temp)/1000, 'f', 2, 64), "°C")
|
||||
press, _ := sensor.ReadPressure()
|
||||
println("Pressure:", strconv.FormatFloat(float64(press)/100000, 'f', 2, 64), "hPa")
|
||||
hum, _ := sensor.ReadHumidity()
|
||||
|
||||
@@ -27,7 +27,7 @@ func main() {
|
||||
println("Error reading temperature", err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("Temperature: %.2f °C\n", t.Celsius())
|
||||
fmt.Printf("Temperature: %.2f °C\n", float32(t)/1000)
|
||||
|
||||
accelX, accelY, accelZ, err := sensor.ReadAcceleration()
|
||||
if err != nil {
|
||||
|
||||
@@ -22,7 +22,7 @@ func main() {
|
||||
|
||||
for {
|
||||
temp, _ := sensor.ReadTemperature()
|
||||
println("Temperature:", temp.Celsius(), "°C")
|
||||
println("Temperature:", float32(temp)/1000, "°C")
|
||||
|
||||
pressure, _ := sensor.ReadPressure()
|
||||
println("Pressure", float32(pressure)/100000, "hPa")
|
||||
|
||||
@@ -30,7 +30,7 @@ func main() {
|
||||
println("Error reading temperature")
|
||||
}
|
||||
// Temperature in degrees Celsius
|
||||
fmt.Printf("Temperature: %.2f °C\n", t.Celsius())
|
||||
fmt.Printf("Temperature: %.2f °C\n", float32(t)/1000)
|
||||
|
||||
p, err := sensor.ReadPressure()
|
||||
if err != nil {
|
||||
|
||||
@@ -38,13 +38,13 @@ func main() {
|
||||
}
|
||||
|
||||
for {
|
||||
temp, err := sensor.ReadTemperature() // returns the temperature in millicelsius
|
||||
temp, err := sensor.ReadTemperature() // returns the temperature in centicelsius
|
||||
press, err := sensor.ReadPressure() // returns the pressure in centipascals
|
||||
|
||||
if err != nil {
|
||||
println(err)
|
||||
} else {
|
||||
println("Temperature:", temp/1000, "C")
|
||||
println("Temperature: " + strconv.FormatInt(int64(temp), 10) + " cC")
|
||||
println("Pressure: " + strconv.FormatInt(int64(press), 10) + " cPa\n")
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ func main() {
|
||||
fmt.Printf("Date: %d/%s/%02d %02d:%02d:%02d \r\n", dt.Year(), dt.Month(), dt.Day(), dt.Hour(), dt.Minute(), dt.Second())
|
||||
}
|
||||
temp, _ := rtc.ReadTemperature()
|
||||
fmt.Printf("Temperature: %.2f °C \r\n", temp.Celsius())
|
||||
fmt.Printf("Temperature: %.2f °C \r\n", float32(temp)/1000)
|
||||
|
||||
time.Sleep(time.Second * 1)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import "tinygo.org/x/drivers/espnet"
|
||||
|
||||
func main() {
|
||||
err := espnet.WiFi.Configure(espnet.Config{})
|
||||
if err != nil {
|
||||
println("failed to configure:", err.Error())
|
||||
}
|
||||
mac, err := espnet.WiFi.AccessPointMAC()
|
||||
if err != nil {
|
||||
println("failed to read MAC address:", err.Error())
|
||||
return
|
||||
}
|
||||
print("MAC address:")
|
||||
for _, b := range mac {
|
||||
print(" ", b)
|
||||
}
|
||||
println()
|
||||
}
|
||||
@@ -23,8 +23,8 @@ func main() {
|
||||
println("Acceleration:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000)
|
||||
x, y, z = accel.ReadRotation()
|
||||
println("Gyroscope:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000)
|
||||
t, _ := accel.ReadTemperature()
|
||||
println("Degrees C", t.Celsius(), "\n\n")
|
||||
x, _ = accel.ReadTemperature()
|
||||
println("Degrees C", float32(x)/1000, "\n\n")
|
||||
time.Sleep(time.Millisecond * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/lsm6dsox"
|
||||
)
|
||||
|
||||
@@ -77,7 +76,7 @@ func calibrateGyro(device *lsm6dsox.Device) {
|
||||
}
|
||||
|
||||
// Arduino IDE's Serial Plotter
|
||||
func printPlotter(ax, ay, az, gx, gy, gz int32, t drivers.Temperature) {
|
||||
func printPlotter(ax, ay, az, gx, gy, gz, t int32) {
|
||||
if SHOW_ACCELERATION {
|
||||
fmt.Printf("AX:%f, AY:%f, AZ:%f,", axis(ax, 0), axis(ay, 0), axis(az, 0))
|
||||
}
|
||||
@@ -85,7 +84,7 @@ func printPlotter(ax, ay, az, gx, gy, gz int32, t drivers.Temperature) {
|
||||
fmt.Printf("GX:%f, GY:%f, GZ:%f,", axis(gx, cal[0]), axis(gy, cal[1]), axis(gz, cal[2]))
|
||||
}
|
||||
if SHOW_TEMPERATURE {
|
||||
fmt.Printf("T:%f", t.Celsius())
|
||||
fmt.Printf("T:%f", float32(t)/1000)
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func main() {
|
||||
println("Magnetic readings:", x, y, z)
|
||||
|
||||
c, _ := mag.ReadTemperature()
|
||||
println("Temperature:", c.Celsius(), "°C")
|
||||
println("Temperature:", float32(c)/1000, "°C")
|
||||
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func main() {
|
||||
|
||||
temp, _ := thermo.ReadTemperature()
|
||||
|
||||
print(fmt.Sprintf("%.2f°C\r\n", temp.Celsius()))
|
||||
print(fmt.Sprintf("%.2f°C\r\n", float32(temp)/1000.0))
|
||||
|
||||
time.Sleep(time.Millisecond * 1000)
|
||||
}
|
||||
|
||||
@@ -191,14 +191,14 @@ func (d *Device) ReadCompass() (h int32) {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in Celsius milli degrees (°C/1000)
|
||||
func (d *Device) ReadTemperature() (c drivers.Temperature, e error) {
|
||||
func (d *Device) ReadTemperature() (c int32, e error) {
|
||||
|
||||
data1, data2 := []byte{0}, []byte{0}
|
||||
d.bus.ReadRegister(uint8(d.AccelAddress), OUT_TEMP_H_A, data1)
|
||||
d.bus.ReadRegister(uint8(d.AccelAddress), OUT_TEMP_L_A, data2)
|
||||
|
||||
t := int16((uint16(data1[0])<<8 | uint16(data2[0]))) >> 4 // temperature offsef from 25 °C
|
||||
c = drivers.Temperature(t)*125 + 25000
|
||||
c = int32((float32(25) + float32(t)/8) * 1000)
|
||||
e = nil
|
||||
return
|
||||
}
|
||||
|
||||
+2
-2
@@ -165,13 +165,13 @@ func (d *Device) ReadRotation() (x int32, y int32, z int32) {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000)
|
||||
func (d *Device) ReadTemperature() (drivers.Temperature, error) {
|
||||
func (d *Device) ReadTemperature() (int32, error) {
|
||||
d.bus.ReadRegister(uint8(d.Address), OUT_TEMP_L, d.dataBufferTwo)
|
||||
|
||||
// From "Table 5. Temperature sensor characteristics"
|
||||
// temp = value/16 + 25
|
||||
t := 25000 + (int32(int16((int16(d.dataBufferTwo[1])<<8)|int16(d.dataBufferTwo[0])))*125)/2
|
||||
return drivers.Temperature(t), nil
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// ReadSteps returns the steps of the pedometer
|
||||
|
||||
@@ -110,11 +110,11 @@ func (d *Device) ReadRotation() (x int32, y int32, z int32) {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000)
|
||||
func (d *Device) ReadTemperature() (drivers.Temperature, error) {
|
||||
func (d *Device) ReadTemperature() (int32, error) {
|
||||
d.bus.ReadRegister(uint8(d.Address), OUT_TEMP_L, d.dataBufferTwo)
|
||||
|
||||
// From "Table 4. Temperature sensor characteristics"
|
||||
// temp = value/256 + 25
|
||||
t := 25000 + (int32(int16((int16(d.dataBufferTwo[1])<<8)|int16(d.dataBufferTwo[0])))*125)/32
|
||||
return drivers.Temperature(t), nil
|
||||
return t, nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -49,8 +49,8 @@ func (d Device) ReadMagnetic() (x int16, y int16, z int16) {
|
||||
|
||||
// ReadTemperature reads and returns the current die temperature in
|
||||
// celsius milli degrees (°C/1000).
|
||||
func (d Device) ReadTemperature() (drivers.Temperature, error) {
|
||||
func (d Device) ReadTemperature() (int32, error) {
|
||||
data := make([]byte, 1)
|
||||
d.bus.ReadRegister(uint8(d.Address), DIE_TEMP, data)
|
||||
return drivers.Temperature(data[0]) * 1000, nil
|
||||
return int32(data[0]) * 1000, nil
|
||||
}
|
||||
|
||||
+5
-5
@@ -31,9 +31,9 @@ func New(bus drivers.I2C) Device {
|
||||
}
|
||||
|
||||
// Read returns the temperature in celsius milli degrees (°C/1000).
|
||||
func (d *Device) ReadTemperature() (tempMilliCelsius drivers.Temperature, err error) {
|
||||
func (d *Device) ReadTemperature() (tempMilliCelsius int32, err error) {
|
||||
tempMilliCelsius, _, err = d.ReadTemperatureHumidity()
|
||||
return drivers.Temperature(tempMilliCelsius), err
|
||||
return tempMilliCelsius, err
|
||||
}
|
||||
|
||||
// Read returns the relative humidity in hundredths of a percent.
|
||||
@@ -43,15 +43,15 @@ func (d *Device) ReadHumidity() (relativeHumidity int16, err error) {
|
||||
}
|
||||
|
||||
// Read returns both the temperature and relative humidity.
|
||||
func (d *Device) ReadTemperatureHumidity() (tempMilliCelsius drivers.Temperature, relativeHumidity int16, err error) {
|
||||
func (d *Device) ReadTemperatureHumidity() (tempMilliCelsius int32, relativeHumidity int16, err error) {
|
||||
var rawTemp, rawHum, errx = d.rawReadings()
|
||||
if errx != nil {
|
||||
err = errx
|
||||
return
|
||||
}
|
||||
tempMilliCelsius = drivers.Temperature((35000 * int32(rawTemp) / 13107) - 45000)
|
||||
tempMilliCelsius = (35000 * int32(rawTemp) / 13107) - 45000
|
||||
relativeHumidity = int16(2000 * int32(rawHum) / 13107)
|
||||
return
|
||||
return tempMilliCelsius, relativeHumidity, err
|
||||
}
|
||||
|
||||
// rawReadings returns the sensor's raw values of the temperature and humidity
|
||||
|
||||
@@ -29,8 +29,6 @@ package thermistor // import "tinygo.org/x/drivers/thermistor"
|
||||
import (
|
||||
"machine"
|
||||
"math"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
)
|
||||
|
||||
// Device holds the ADC pin and the needed settings for calculating the
|
||||
@@ -63,7 +61,7 @@ func (d *Device) Configure() {
|
||||
}
|
||||
|
||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000)
|
||||
func (d *Device) ReadTemperature() (temperature drivers.Temperature, err error) {
|
||||
func (d *Device) ReadTemperature() (temperature int32, err error) {
|
||||
var reading uint32
|
||||
if d.HighSide {
|
||||
// Thermistor connected from analog input to high logic level.
|
||||
@@ -84,5 +82,5 @@ func (d *Device) ReadTemperature() (temperature drivers.Temperature, err error)
|
||||
steinhart = 1.0 / steinhart // Invert
|
||||
steinhart -= 273.15 // convert to C
|
||||
|
||||
return drivers.Temperature(steinhart * 1000), nil
|
||||
return int32(steinhart * 1000), nil
|
||||
}
|
||||
|
||||
+3
-3
@@ -46,7 +46,7 @@ func (d *Device) Connected() bool {
|
||||
}
|
||||
|
||||
// Reads the temperature from the sensor and returns it in celsius milli degrees (°C/1000).
|
||||
func (d *Device) ReadTemperature() (temperature drivers.Temperature, err error) {
|
||||
func (d *Device) ReadTemperature() (temperature int32, err error) {
|
||||
|
||||
tmpData := make([]byte, 2)
|
||||
|
||||
@@ -62,7 +62,7 @@ func (d *Device) ReadTemperature() (temperature drivers.Temperature, err error)
|
||||
temperatureSum |= int32(0xf800)
|
||||
}
|
||||
|
||||
temperature = drivers.Temperature(temperatureSum * 625 / 10)
|
||||
temperature = temperatureSum * 625
|
||||
|
||||
return temperature, nil
|
||||
return temperature / 10, nil
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package drivers
|
||||
|
||||
// This file contains some common units that can be used in a sensor driver.
|
||||
|
||||
// Temperature is a temperature in Celsius milli degrees (°C/1000). For example,
|
||||
// the value 25000 is 25°C.
|
||||
type Temperature int32
|
||||
|
||||
// Celsius returns the temperature in degrees Celsius.
|
||||
func (t Temperature) Celsius() float32 {
|
||||
return float32(t) / 1000
|
||||
}
|
||||
|
||||
// Fahrenheit returns the temperature in degrees Fahrenheit.
|
||||
func (t Temperature) Fahrenheit() float32 {
|
||||
return t.Celsius()*1.8 + 32
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package drivers
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTemperature(t *testing.T) {
|
||||
tests := []struct {
|
||||
t Temperature
|
||||
c float32 // Celsius
|
||||
f float32 // Fahrenheit
|
||||
}{
|
||||
{-40000, -40, -40}, // -40°C
|
||||
{0, 0, 32}, // 0°C
|
||||
{20000, 20, 68}, // 20°C
|
||||
{25000, 25, 77}, // 25°C
|
||||
}
|
||||
for _, tc := range tests {
|
||||
c := tc.t.Celsius()
|
||||
f := tc.t.Fahrenheit()
|
||||
if c != tc.c {
|
||||
t.Errorf("expected value %d to be %f°C, but got %f°C", tc.t, tc.c, c)
|
||||
}
|
||||
if f != tc.f {
|
||||
t.Errorf("expected value %d to be %f°F, but got %f°F", tc.t, tc.f, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user