!184 PikaStdDevice_v2.1.1_1669811604831

Merge pull request !184 from pikabot/PikaStdDevice_v2.1.1_1669811604831
This commit is contained in:
李昂 2022-11-30 12:37:58 +00:00 committed by Gitee
commit c0695d75ff
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 106 additions and 1 deletions

View File

@ -169,6 +169,24 @@ class ADC(BaseDev):
def platformDisable(self): ...
class DAC(BaseDev):
def __init__(self): ...
def setPin(self, pin: str):
"""
Use the name of the pin to select the DAC pin.
example: `"PA0"`, `"PA1"` ...
"""
def enable(self):
"""Enable the DAC."""
def disable(self):
"""Disable the DAC."""
def write(self, val:float):
"""write the DAC value."""
class UART(BaseDev):
def __init__(self): ...

View File

@ -0,0 +1,48 @@
#include "PikaStdDevice_DAC.h"
#include "BaseObj.h"
#include "pika_hal.h"
static pika_dev* _get_dev(PikaObj* self) {
pika_dev* dev = obj_getPtr(self, "pika_dev");
if (NULL != dev) {
return dev;
}
dev = pika_hal_open(PIKA_HAL_DAC, obj_getStr(self, "pin"));
if (NULL == dev) {
__platform_printf("Error: open DAC '%s' failed.\r\n",
obj_getStr(self, "pin"));
}
obj_setPtr(self, "pika_dev", dev);
return dev;
}
void PikaStdDevice_DAC_enable(PikaObj* self) {
pika_dev* dev = _get_dev(self);
pika_hal_DAC_config cfg = {0};
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
}
void PikaStdDevice_DAC_setPin(PikaObj* self, char* pin) {
obj_setStr(self, "pin", pin);
}
void PikaStdDevice_DAC_disable(PikaObj* self) {
pika_dev* dev = _get_dev(self);
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
}
void PikaStdDevice_DAC_init(PikaObj* self) {
obj_setStr(self, "pin", "PA0");
}
void PikaStdDevice_DAC___init__(PikaObj* self) {
PikaStdDevice_DAC_init(self);
}
void PikaStdDevice_DAC_write(PikaObj* self, pika_float val) {
pika_dev* dev = _get_dev(self);
pika_hal_DAC_config* cfg = (pika_hal_DAC_config*)dev->ioctl_config;
uint32_t val_i = (val / cfg->vref) * cfg->max;
pika_hal_write(dev, &val_i, sizeof val_i);
}

View File

@ -203,6 +203,7 @@ int pika_hal_SPI_ioctl_merge_config(pika_hal_SPI_config* dst,
_IOCTL_CONFIG_USE_DEFAULT(mode, PIKA_HAL_SPI_MODE_0);
_IOCTL_CONFIG_USE_DEFAULT(data_width, PIKA_HAL_SPI_DATA_WIDTH_8);
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_SPI_SPEED_2M);
_IOCTL_CONFIG_USE_DEFAULT(timeout, PIKA_HAL_SPI_TIMEOUT_1000MS);
return 0;
}
@ -239,6 +240,9 @@ int pika_hal_ADC_ioctl_merge_config(pika_hal_ADC_config* dst,
int pika_hal_DAC_ioctl_merge_config(pika_hal_DAC_config* dst,
pika_hal_DAC_config* src) {
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_DAC_SPEED_1K * 8);
_IOCTL_CONFIG_USE_DEFAULT(sampling_resolution, PIKA_HAL_DAC_RESOLUTION_12);
_IOCTL_CONFIG_USE_DEFAULT(vref, (pika_float)3.3);
_IOCTL_CONFIG_USE_DEFAULT(max, 3300000);
return 0;
}

View File

@ -167,6 +167,20 @@ typedef struct {
PIKA_HAL_IIC_TIMEOUT timeout;
} pika_hal_IIC_config;
typedef enum PIKA_HAL_SPI_TIMEOUT {
_PIKA_HAL_SPI_TIMEOUT_UNUSED = 0,
PIKA_HAL_SPI_TIMEOUT_1MS = 1,
PIKA_HAL_SPI_TIMEOUT_2MS = 2,
PIKA_HAL_SPI_TIMEOUT_5MS = 5,
PIKA_HAL_SPI_TIMEOUT_10MS = 10,
PIKA_HAL_SPI_TIMEOUT_20MS = 20,
PIKA_HAL_SPI_TIMEOUT_50MS = 50,
PIKA_HAL_SPI_TIMEOUT_100MS = 100,
PIKA_HAL_SPI_TIMEOUT_200MS = 200,
PIKA_HAL_SPI_TIMEOUT_500MS = 500,
PIKA_HAL_SPI_TIMEOUT_1000MS = 1000,
} PIKA_HAL_SPI_TIMEOUT;
typedef enum {
_PIKA_HAL_SPI_LSB_OR_MSB_UNUSED = 0,
PIKA_HAL_SPI_LSB,
@ -210,6 +224,7 @@ typedef struct {
PIKA_HAL_SPI_MODE mode;
PIKA_HAL_SPI_DATA_WIDTH data_width;
PIKA_HAL_SPI_SPEED speed;
PIKA_HAL_SPI_TIMEOUT timeout;
} pika_hal_SPI_config;
typedef enum {
@ -257,8 +272,27 @@ typedef enum {
PIKA_HAL_DAC_RESOLUTION_16 = 16,
} PIKA_HAL_DAC_RESOLUTION;
typedef enum PIKA_HAL_DAC_SPEED {
_PIKA_HAL_DAC_SPEED_UNUSED = 0,
PIKA_HAL_DAC_SPEED_100 = 100,
PIKA_HAL_DAC_SPEED_1K = 1000,
PIKA_HAL_DAC_SPEED_10K = 10000,
PIKA_HAL_DAC_SPEED_100K = 100000,
PIKA_HAL_DAC_SPEED_1M = 1000000,
PIKA_HAL_DAC_SPEED_10M = 10000000,
PIKA_HAL_DAC_SPEED_20M = 20000000,
PIKA_HAL_DAC_SPEED_50M = 50000000,
PIKA_HAL_DAC_SPEED_100M = 100000000,
} PIKA_HAL_DAC_SPEED;
typedef pika_float PIKA_HAL_DAC_VREF;
typedef uint32_t PIKA_HAL_DAC_MAX;
typedef struct pika_hal_DAC_config {
PIKA_HAL_DAC_RESOLUTION sampling_resolution;
PIKA_HAL_DAC_SPEED speed;
PIKA_HAL_DAC_MAX max;
PIKA_HAL_DAC_VREF vref;
} pika_hal_DAC_config;
typedef enum {

View File

@ -168,7 +168,8 @@ releases = [
"v1.11.7 b7112610bb29109fd7268bf7162004561d73daa1",
"v1.11.8 58ff9fe16688be2e77ed220604aa8b1271b72d80",
"v2.0.0 e89c585f46ee98811611ea56d5abfc618a41ee3b",
"v2.1.0 852daad3c9a95dbce54dbf1d2cdb5b2321826b4f"
"v2.1.0 852daad3c9a95dbce54dbf1d2cdb5b2321826b4f",
"v2.1.1 5eadba95fa573e3409f65c6392804d3c60d627ac"
]
[[packages]]