Skip to content

Commit 4b0ff2f

Browse files
committed
first commit
1 parent bbde37f commit 4b0ff2f

200 files changed

Lines changed: 8974 additions & 3728 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CHANGE LOG
2+
3+
**28-Sep-2024**
4+
1. Added support for GT911 touch controller. See [multi-touch example](./src/twi/gt911) and [LVGL-example](./src/gui/lvgl9).
5+
2. The LWIP-library version has been updated to release 2.2.0.
6+
7+
8+

common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ MKSUNXI = "$(BASE)tools\sunxi\mksunxi"
2222

2323
all: out $(BOOT).bin $(NAME).bin
2424
$(CC)size -G out/*.elf
25-
run: all
25+
run: #all
2626
$(FEL) -p spl $(BOOT).bin
2727
$(FEL) -p write 0x80000000 $(NAME).bin
2828
$(FEL) exec 0x80000000

drv/twi.c

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,78 @@ static int ns2009_rd (struct TWI_DEV *dev, u8 cmd, u32 *dat)
278278
int ns2009_read (struct TWI_DEV *dev)
279279
{
280280
u32 x, y, z;
281-
struct TS *ts = (struct TS *)dev->data;
282-
if(ns2009_rd(dev, NS2009_RD_Z1, &z) == KO) return KO;
283-
if(ns2009_rd(dev, NS2009_RD_X, &x) == KO) return KO;
284-
if(ns2009_rd(dev, NS2009_RD_Y, &y) == KO) return KO;
281+
struct TS_NS2009 *ts = (struct TS_NS2009 *)dev->data;
282+
if(ns2009_rd(dev, NS2009_RD_Z1, &z) == KO) return 0;
283+
if(ns2009_rd(dev, NS2009_RD_X, &x) == KO) return 0;
284+
if(ns2009_rd(dev, NS2009_RD_Y, &y) == KO) return 0;
285285
ts->z <<= 1;
286-
if(z < ts->dz) return KO;
286+
if(z < ts->dz) return 0;
287287
ts->z |= 1;
288+
//printf("%03d %03d %03d\r", x, y, z);
288289
if(x < ts->x1) x = ts->x1; else if(x > ts->x2) x = ts->x2;
289290
if(y < ts->y1) y = ts->y1; else if(y > ts->y2) y = ts->y2;
290291
x = (x - ts->x1) * (display->width - 1) / (ts->x2 - ts->x1);
291292
y = (y - ts->y1) * (display->height - 1) / (ts->y2 - ts->y1);
292293
ts_buf_update(ts->bufx, x);
293294
ts_buf_update(ts->bufy, y);
294-
if((ts->z & 0x1F) != 0x1F) return KO;
295+
if((ts->z & 0x1F) != 0x1F) return 0;
295296
ts->x = ts_get_median(ts->bufx);
296297
ts->y = display->height - ts_get_median(ts->bufy);
297-
return OK;
298+
return 1;
299+
}
300+
301+
/*******************************************************************************
302+
TS GT911
303+
*******************************************************************************/
304+
int gt911_rd (struct TWI_DEV *dev, u16 addr, void *dat, u32 len)
305+
{
306+
u8 buf[2] = { addr >> 8, addr };
307+
twi_start(dev->bus, dev->addr & 0xFE);
308+
twi_send(dev->bus, buf, 2);
309+
twi_stop(dev->bus);
310+
if(!twi_error)
311+
{
312+
twi_start(dev->bus, dev->addr | 1);
313+
twi_recv(dev->bus, dat, len);
314+
twi_stop(dev->bus);
315+
}
316+
return twi_error ? KO : OK;
317+
}
318+
319+
int gt911_wr (struct TWI_DEV *dev, u16 addr, void *dat, u32 len)
320+
{
321+
u8 buf[2] = { addr >> 8, addr };
322+
twi_start(dev->bus, dev->addr & 0xFE);
323+
twi_send(dev->bus, buf, 2);
324+
twi_send(dev->bus, dat, 1);
325+
twi_stop(dev->bus);
326+
return twi_error ? KO : OK;
327+
}
328+
329+
int gt911_read (struct TWI_DEV *dev)
330+
{
331+
u8 stat;
332+
u16 x, y, z;
333+
struct TS_GT911 *ts = (struct TS_GT911 *)dev->data;
334+
if(gt911_rd(dev, 0x814e, &stat, sizeof(stat)) == KO) return 0;
335+
if(!(stat & 0x80)) return 0;
336+
stat &= 15;
337+
for(int addr = 0x8150, i = 0; i < stat; i++)
338+
{
339+
if(gt911_rd(dev, addr, &x, sizeof(x)) == KO) return 0;
340+
if(gt911_rd(dev, addr + 2, &y, sizeof(y)) == KO) return 0;
341+
if(gt911_rd(dev, addr + 4, &z, sizeof(z)) == KO) return 0;
342+
addr += 8;
343+
//printf("pt%d:%d*%d*%d ", i, x, y, z);
344+
if(x < ts->x1) x = ts->x1; else if(x > ts->x2) x = ts->x2;
345+
if(y < ts->y1) y = ts->y1; else if(y > ts->y2) y = ts->y2;
346+
x = (x - ts->x1) * (display->width - 1) / (ts->x2 - ts->x1);
347+
y = (y - ts->y1) * (display->height - 1) / (ts->y2 - ts->y1);
348+
ts->pt[i].x = x;
349+
ts->pt[i].y = y;
350+
ts->pt[i].z = z;
351+
}
352+
z = 0;
353+
gt911_wr(dev, 0x814e, &z, 1);
354+
return stat;
298355
}

drv/twi.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void twi_write_start (TWI_T *TWI, char dev_addr, char reg_addr);
3333
void twi_read_start (TWI_T *TWI, char dev_addr, char reg_addr);
3434

3535
/* RTC PCF8563 (BM8563) */
36-
#define PCF8563_ADDR 0xA2
36+
#define PCF8563_ADDR 0xA2
3737

3838
struct TM {
3939
u8 sec; // 00:59
@@ -51,19 +51,38 @@ int pcf8563_read_tm (struct TWI_DEV *dev);
5151
int pcf8563_write_tm (struct TWI_DEV *dev);
5252

5353
/* TS NS2009 */
54-
#define NS2009_ADDR0 0x90
55-
#define NS2009_ADDR1 0x91
56-
#define NS2009_TS_INIT { 0, 0, 0, 150, 3960, 140, 3800, 80 }
54+
#define NS2009_ADDR 0x90
55+
#define NS2009_TS_INIT { 150, 3960, 140, 3800, 80 }
5756

58-
struct TS {
59-
u32 x, y, z; // X, Y - real coordinates, Z - touch history
57+
struct TS_NS2009 {
6058
u32 x1, x2; // X - borders
6159
u32 y1, y2; // Y - borders
6260
u32 dz; // Z - threshold
6361
u32 bufx[5]; // X - fifo buffer
6462
u32 bufy[5]; // Y - fifo buffer
63+
u32 x, y, z; // X, Y - real coordinates, Z - touch history
6564
};
6665

6766
int ns2009_read (struct TWI_DEV *dev);
6867

68+
/* TS GT911 */
69+
#if 1
70+
#define GT911_ADDR 0xBA
71+
#else
72+
#define GT911_ADDR 0x28
73+
#endif
74+
#define GT911_TS_INIT { 0, 799, 0, 479 };
75+
76+
struct TS_GT911 {
77+
u32 x1, x2; // X - borders
78+
u32 y1, y2; // Y - borders
79+
struct {
80+
u32 x, y, z;// X, Y - real coordinates, Z - point size
81+
} pt[5];
82+
};
83+
84+
int gt911_rd (struct TWI_DEV *dev, u16 addr, void *dat, u32 len);
85+
int gt911_wr (struct TWI_DEV *dev, u16 addr, void *dat, u32 len);
86+
int gt911_read (struct TWI_DEV *dev);
87+
6988
#endif

lib/lwip/api/api_lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port)
323323
* and NETCONN_FLAG_IPV6_V6ONLY is 0, use IP_ANY_TYPE to bind
324324
*/
325325
if ((netconn_get_ipv6only(conn) == 0) &&
326-
ip_addr_cmp(addr, IP6_ADDR_ANY)) {
326+
ip_addr_eq(addr, IP6_ADDR_ANY)) {
327327
addr = IP_ANY_TYPE;
328328
}
329329
#endif /* LWIP_IPV4 && LWIP_IPV6 */
@@ -1260,13 +1260,13 @@ netconn_join_leave_group_netif(struct netconn *conn,
12601260
*
12611261
* @param name a string representation of the DNS host name to query
12621262
* @param addr a preallocated ip_addr_t where to store the resolved IP address
1263-
* @param dns_addrtype IP address type (IPv4 / IPv6)
12641263
* @return ERR_OK: resolving succeeded
12651264
* ERR_MEM: memory error, try again later
12661265
* ERR_ARG: dns client not initialized or invalid hostname
12671266
* ERR_VAL: dns server response was invalid
12681267
*/
12691268
#if LWIP_IPV4 && LWIP_IPV6
1269+
/** @param dns_addrtype IP address type (IPv4 / IPv6) */
12701270
err_t
12711271
netconn_gethostbyname_addrtype(const char *name, ip_addr_t *addr, u8_t dns_addrtype)
12721272
#else

lib/lwip/api/api_msg.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void netconn_drain(struct netconn *conn);
9393
#endif /* LWIP_TCPIP_CORE_LOCKING */
9494

9595
#if LWIP_NETCONN_FULLDUPLEX
96-
const u8_t netconn_deleted = 0;
96+
static const u8_t netconn_deleted = 0;
9797

9898
int
9999
lwip_netconn_is_deallocated_msg(void *msg)
@@ -106,9 +106,9 @@ lwip_netconn_is_deallocated_msg(void *msg)
106106
#endif /* LWIP_NETCONN_FULLDUPLEX */
107107

108108
#if LWIP_TCP
109-
const u8_t netconn_aborted = 0;
110-
const u8_t netconn_reset = 0;
111-
const u8_t netconn_closed = 0;
109+
static const u8_t netconn_aborted = 0;
110+
static const u8_t netconn_reset = 0;
111+
static const u8_t netconn_closed = 0;
112112

113113
/** Translate an error to a unique void* passed via an mbox */
114114
static void *
@@ -221,6 +221,7 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
221221
struct netbuf *buf;
222222
struct netconn *conn;
223223
u16_t len;
224+
err_t err;
224225
#if LWIP_SO_RCVBUF
225226
int recv_avail;
226227
#endif /* LWIP_SO_RCVBUF */
@@ -269,8 +270,10 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
269270
}
270271

271272
len = p->tot_len;
272-
if (sys_mbox_trypost(&conn->recvmbox, buf) != ERR_OK) {
273+
err = sys_mbox_trypost(&conn->recvmbox, buf);
274+
if (err != ERR_OK) {
273275
netbuf_delete(buf);
276+
LWIP_DEBUGF(API_MSG_DEBUG, ("recv_udp: sys_mbox_trypost failed, err=%d\n", err));
274277
return;
275278
} else {
276279
#if LWIP_SO_RCVBUF
@@ -469,7 +472,7 @@ err_tcp(void *arg, err_t err)
469472
}
470473
/* pass error message to acceptmbox to wake up pending accept */
471474
if (NETCONN_MBOX_VALID(conn, &conn->acceptmbox)) {
472-
/* use trypost to preven deadlock */
475+
/* use trypost to prevent deadlock */
473476
sys_mbox_trypost(&conn->acceptmbox, mbox_msg);
474477
}
475478

@@ -492,7 +495,7 @@ err_tcp(void *arg, err_t err)
492495
conn->current_msg->err = err;
493496
}
494497
op_completed_sem = LWIP_API_MSG_SEM(conn->current_msg);
495-
LWIP_ASSERT("inavlid op_completed_sem", sys_sem_valid(op_completed_sem));
498+
LWIP_ASSERT("invalid op_completed_sem", sys_sem_valid(op_completed_sem));
496499
conn->current_msg = NULL;
497500
/* wake up the waiting task */
498501
sys_sem_signal(op_completed_sem);
@@ -759,10 +762,8 @@ netconn_alloc(enum netconn_type t, netconn_callback callback)
759762
sys_mbox_set_invalid(&conn->acceptmbox);
760763
#endif
761764
conn->state = NETCONN_NONE;
762-
#if LWIP_SOCKET
763765
/* initialize socket to -1 since 0 is a valid socket */
764-
conn->socket = -1;
765-
#endif /* LWIP_SOCKET */
766+
conn->callback_arg.socket = -1;
766767
conn->callback = callback;
767768
#if LWIP_TCP
768769
conn->current_msg = NULL;
@@ -978,7 +979,7 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
978979
/* Try to close the connection */
979980
if (shut_close) {
980981
#if LWIP_SO_LINGER
981-
/* check linger possibilites before calling tcp_close */
982+
/* check linger possibilities before calling tcp_close */
982983
err = ERR_OK;
983984
/* linger enabled/required at all? (i.e. is there untransmitted data left?) */
984985
if ((conn->linger >= 0) && (conn->pcb.tcp->unsent || conn->pcb.tcp->unacked)) {
@@ -1472,7 +1473,7 @@ lwip_netconn_do_listen(void *m)
14721473
/* "Socket API like" dual-stack support: If IP to listen to is IP6_ADDR_ANY,
14731474
* and NETCONN_FLAG_IPV6_V6ONLY is NOT set, use IP_ANY_TYPE to listen
14741475
*/
1475-
if (ip_addr_cmp(&msg->conn->pcb.ip->local_ip, IP6_ADDR_ANY) &&
1476+
if (ip_addr_eq(&msg->conn->pcb.ip->local_ip, IP6_ADDR_ANY) &&
14761477
(netconn_get_ipv6only(msg->conn) == 0)) {
14771478
/* change PCB type to IPADDR_TYPE_ANY */
14781479
IP_SET_TYPE_VAL(msg->conn->pcb.tcp->local_ip, IPADDR_TYPE_ANY);

lib/lwip/api/if_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ lwip_if_indextoname(unsigned int ifindex, char *ifname)
7777

7878
/**
7979
* @ingroup if_api
80-
* Returs the interface index corresponding to name ifname.
80+
* Returns the interface index corresponding to name ifname.
8181
* @param ifname Interface name
8282
* @return The corresponding index if ifname is the name of an interface;
8383
* otherwise, zero.

lib/lwip/api/netbuf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* @defgroup netbuf Network buffers
66
* @ingroup netconn
77
* Network buffer descriptor for @ref netconn. Based on @ref pbuf internally
8-
* to avoid copying data around.\n
9-
* Buffers must not be shared accross multiple threads, all functions except
8+
* to avoid copying data around.<br>
9+
* Buffers must not be shared across multiple threads, all functions except
1010
* netbuf_new() and netbuf_delete() are not thread-safe.
1111
*/
1212

lib/lwip/api/netdb.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,18 @@ struct gethostbyname_r_helper {
6161
int h_errno;
6262
#endif /* LWIP_DNS_API_DECLARE_H_ERRNO */
6363

64-
/** define "hostent" variables storage: 0 if we use a static (but unprotected)
65-
* set of variables for lwip_gethostbyname, 1 if we use a local storage */
64+
/** LWIP_DNS_API_HOSTENT_STORAGE: if set to 0 (default), lwip_gethostbyname()
65+
* returns the same global variabe for all calls (in all threads).
66+
* When set to 1, your port should provide a function
67+
* struct hostent* sys_thread_hostent( struct hostent* h);
68+
* which have to do a copy of "h" and return a pointer ont the "per-thread"
69+
* copy.
70+
*/
6671
#ifndef LWIP_DNS_API_HOSTENT_STORAGE
6772
#define LWIP_DNS_API_HOSTENT_STORAGE 0
6873
#endif
6974

70-
/** define "hostent" variables storage */
75+
/* define "hostent" variables storage */
7176
#if LWIP_DNS_API_HOSTENT_STORAGE
7277
#define HOSTENT_STORAGE
7378
#else

0 commit comments

Comments
 (0)