Skip to content

Commit 98eb666

Browse files
dmascordMrJake222
authored andcommitted
ports/esp8266: Added implementation for ioctl.
select.select now works.
1 parent 2fdf6d9 commit 98eb666

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

ports/esp8266/machine_softuart.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,21 @@ STATIC mp_uint_t pyb_softuart_write(mp_obj_t self_in, const void *buf_in, mp_uin
223223
}
224224

225225
STATIC mp_uint_t pyb_softuart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
226-
*errcode = MP_EINVAL;
227-
return MP_STREAM_ERROR;
226+
mp_uint_t ret;
227+
if (request == MP_STREAM_POLL) {
228+
mp_uint_t flags = arg;
229+
ret = 0;
230+
if ((flags & MP_STREAM_POLL_RD) && Softuart_rx_any(&softuartDevice)) {
231+
ret |= MP_STREAM_POLL_RD;
232+
}
233+
if ((flags & MP_STREAM_POLL_WR) && Softuart_tx_any_room(&softuartDevice)) {
234+
ret |= MP_STREAM_POLL_WR;
235+
}
236+
} else {
237+
*errcode = MP_EINVAL;
238+
ret = MP_STREAM_ERROR;
239+
}
240+
return ret;
228241
}
229242

230243
STATIC const mp_stream_p_t softuart_stream_p = {

ports/esp8266/softuart.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,19 @@ uint32_t Softuart_Flush(Softuart *s)
334334
// Is data in buffer available?
335335
BOOL Softuart_Available(Softuart *s)
336336
{
337-
return (s->buffer.receive_buffer_tail + SOFTUART_MAX_RX_BUFF - s->buffer.receive_buffer_head) % SOFTUART_MAX_RX_BUFF;
337+
return (s->buffer.receive_buffer_tail + SOFTUART_MAX_RX_BUFF - s->buffer.receive_buffer_head) % SOFTUART_MAX_RX_BUFF;
338338
}
339339

340+
int Softuart_rx_any(Softuart *s) {
341+
return (Softuart_Available(s));
342+
}
343+
344+
int Softuart_tx_any_room(Softuart *s) {
345+
// TODO always assume we have room... there is no send buffer
346+
return true;
347+
}
348+
349+
340350
// cversek:
341351
// based on micropython/esp8266/uart.c bool uart_rx_wait(uint32_t timeout_us)
342352
// Waits at most timeout microseconds for at least 1 char to become ready for reading.

ports/esp8266/softuart.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void Softuart_Putchar(Softuart *s, char data);
4545
void Softuart_Puts(Softuart *s, const char *c );
4646
uint8_t Softuart_Read(Softuart *s);
4747
uint8_t Softuart_Readline(Softuart *s, char* Buffer, uint8_t MaxLen );
48+
// check status of rx/tx
49+
int Softuart_rx_any(Softuart *s);
50+
int Softuart_tx_any_room(Softuart *s);
4851

4952
//define mapping from pin to functio mode
5053
typedef struct {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy