8000 esp32/machine_dac.c: Updates per issue #4254a · MrSurly/micropython@ed498c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed498c7

Browse files
committed
esp32/machine_dac.c: Updates per issue #4254a
Updated DAC api per: micropython#4254
1 parent 27ca9ab commit ed498c7

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

ports/esp32/machine_dac.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#include "py/mphal.h"
3737
#include "modmachine.h"
3838

39+
static enum {
40+
CIRCULAR,
41+
SEQUENTIAL
42+
} dac_mode_t;
43+
3944
typedef struct _mdac_obj_t {
4045
mp_obj_base_t base;
4146
gpio_num_t gpio_id;
@@ -47,6 +52,87 @@ STATIC const mdac_obj_t mdac_obj[] = {
4752
{{&machine_dac_type}, GPIO_NUM_26, DAC_CHANNEL_2},
4853
};
4954

55+
56+
#include <stdio.h>
57+
#include <stdlib.h>
58+
59+
#define LOCK()
60+
#define UNLOCK()
61+
62+
typedef struct Qitem {
63+
struct Qitem* next;
64+
void *item;
65+
} Qitem;
66+
67+
typedef struct {
68+
Qitem* head;
69+
Qitem* tail;
70+
size_t size;
71+
mp_obj_t *item;
72+
} Qhead;
73+
74+
void queue_init(Qhead* q) {
75+
q->head = q->tail = NULL;
76+
q->size = 0;
77+
}
78+
79+
int queue_empty(Qhead* q) {
80+
return q->size == 0;
81+
}
82+
int queue_size(Qhead* q) {
83+
return q->size;
84+
}
85+
86+
int queue_push(Qhead* q, mp_obj_t* item) {
87+
LOCK();
88+
Qitem* i = (Qitem*)malloc(sizeof(Qitem));
89+
if (i == NULL) {
90+
return 0;
91+
}
92+
i->item = item;
93+
i->next = NULL;
94+
if (queue_empty(q)) {
95+
q->head = q->tail = i;
96+
} else {
97+
q->tail->next = i;
98+
q->tail = i;
99+
}
100+
size_t s = ++q->size;
101+
UNLOCK();
102+
return s;
103+
}
104+
105+
mp_obj_t* queue_pop(Qhead* q) {
106+
LOCK();
107+
if (queue_empty(q)) {
108+
return NULL;
109+
}
110+
--q->size;
111+
112+
Qitem* i = q->head;
113+
q->head = i->next;
114+
i->next = NULL;
115+
if (q->head == NULL) {
116+
q->tail = NULL;
117+
}
118+
UNLOCK();
119+
return i->item;
120+
}
121+
122+
/*
123+
void queue_dump(Qhead* q) {
124+
printf("---\n");
125+
printf("head: %p\n", q->head);
126+
printf("tail: %p\n", q->tail);
127+
printf("size: %d\n", q->size);
128+
Qitem *i = q->head;
129+
while(i) {
130+
printf("%p: value: %p --> %p\n", i, i->item, i->next);
131+
i = i->next;
132+
}
133+
}
134+
*/
135+
50136
STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
51137
const mp_obj_t *args) {
52138

@@ -84,6 +170,8 @@ MP_DEFINE_CONST_FUN_OBJ_2(mdac_write_obj, mdac_write);
84170

85171
STATIC const mp_rom_map_elem_t mdac_locals_dict_table[] = {
86172
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mdac_write_obj) },
173+
{ MP_ROM_QSTR(MP_QSTR_CIRCULAR), MP_ROM_INT(CIRCULAR) },
174+
{ MP_ROM_QSTR(MP_QSTR_SEQUENTIAL), MP_ROM_INT(SEQUENTIAL) },
87175
};
88176

89177
STATIC MP_DEFINE_CONST_DICT(mdac_locals_dict, mdac_locals_dict_table);

0 commit comments

Comments
 (0)
0