summaryrefslogtreecommitdiff
path: root/src/typec/utcd.c
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-06-09 18:15:28 +0700
committerhathach <[email protected]>2023-06-09 18:15:28 +0700
commit912802456b568e4b666a9205c3799da79f87ef69 (patch)
treeee04bf5ca1248e477c739a96f8573e69dc2ab7f9 /src/typec/utcd.c
parent8181d470e5bbb01f873d8fa11e8e1293cb76703f (diff)
move protocol message to stack, disable battery in PWR's CR3
there is still issue with CC1/CC2 pull down resistor and vstate is not correct.
Diffstat (limited to 'src/typec/utcd.c')
-rw-r--r--src/typec/utcd.c61
1 files changed, 48 insertions, 13 deletions
diff --git a/src/typec/utcd.c b/src/typec/utcd.c
index b5f9965fe..fb69b01e8 100644
--- a/src/typec/utcd.c
+++ b/src/typec/utcd.c
@@ -42,35 +42,38 @@
// Event queue
// utcd_int_set() is used as mutex in OS NONE config
void utcd_int_set(bool enabled);
-OSAL_QUEUE_DEF(utcd_int_set, utcd_qdef, CFG_TUC_TASK_QUEUE_SZ, tcd_event_t);
-tu_static osal_queue_t utcd_q;
+OSAL_QUEUE_DEF(utcd_int_set, _utcd_qdef, CFG_TUC_TASK_QUEUE_SZ, tcd_event_t);
+tu_static osal_queue_t _utcd_q;
// if stack is initialized
-static bool utcd_inited = false;
+static bool _utcd_inited = false;
// if port is initialized
-static bool port_inited[TUP_TYPEC_RHPORTS_NUM];
+static bool _port_inited[TUP_TYPEC_RHPORTS_NUM];
+
+// Max possible PD size is 262 bytes
+static uint8_t _rx_buf[262] TU_ATTR_ALIGNED(4);
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
bool tuc_inited(uint8_t rhport) {
- return utcd_inited && port_inited[rhport];
+ return _utcd_inited && _port_inited[rhport];
}
bool tuc_init(uint8_t rhport, tusb_typec_port_type_t port_type) {
// Initialize stack
- if (!utcd_inited) {
- tu_memclr(port_inited, sizeof(port_inited));
+ if (!_utcd_inited) {
+ tu_memclr(_port_inited, sizeof(_port_inited));
- utcd_q = osal_queue_create(&utcd_qdef);
- TU_ASSERT(utcd_q != NULL);
+ _utcd_q = osal_queue_create(&_utcd_qdef);
+ TU_ASSERT(_utcd_q != NULL);
- utcd_inited = true;
+ _utcd_inited = true;
}
// skip if port already initialized
- if ( port_inited[rhport] ) {
+ if ( _port_inited[rhport] ) {
return true;
}
@@ -79,10 +82,42 @@ bool tuc_init(uint8_t rhport, tusb_typec_port_type_t port_type) {
TU_ASSERT(tcd_init(rhport, port_type));
tcd_int_enable(rhport);
- port_inited[rhport] = true;
+ _port_inited[rhport] = true;
return true;
}
+//--------------------------------------------------------------------+
+//
+//--------------------------------------------------------------------+
+
+//bool parse_message(uint8_t const * data, uint16_t len, pd_msg_t * msg) {
+// // TODO
+// (void) data;
+// (void) len;
+// (void) msg;
+// return false;
+//}
+
+void tcd_event_handler(tcd_event_t const * event, bool in_isr) {
+ (void) in_isr;
+ switch(event->event_id) {
+ case TCD_EVENT_CC_CHANGED:
+ if (event->cc_changed.cc_state[0] || event->cc_changed.cc_state[1]) {
+ // Attach
+ tcd_rx_start(event->rhport, _rx_buf, sizeof(_rx_buf));
+ }else {
+ // Detach
+ }
+ break;
+
+ case TCD_EVENT_RX_COMPLETE:
+ // TODO process message here in ISR, move to thread later
+
+ // start new rx
+ tcd_rx_start(event->rhport, _rx_buf, sizeof(_rx_buf));
+ break;
+ }
+}
//--------------------------------------------------------------------+
//
@@ -90,7 +125,7 @@ bool tuc_init(uint8_t rhport, tusb_typec_port_type_t port_type) {
void utcd_int_set(bool enabled) {
// Disable all controllers since they shared the same event queue
for (uint8_t p = 0; p < TUP_TYPEC_RHPORTS_NUM; p++) {
- if ( port_inited[p] ) {
+ if ( _port_inited[p] ) {
if (enabled) {
tcd_int_enable(p);
}else {