sw: outline of serial device

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2019-05-22 15:26:27 +08:00
parent e8aaac5cfe
commit ba8314c823
6 changed files with 41 additions and 0 deletions

6
sw/include/tester.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef TESTER_H__
#define TESTER_H__
void tester_poll(void);
#endif /* TESTER_H__ */

View File

@ -38,6 +38,8 @@ LGPL License Terms @ref lgpl_license
#ifndef __CDC_H
#define __CDC_H
#include <stdint.h>
/* Definitions of Communications Device Class from
* "Universal Serial Bus Class Definitions for Communications Devices
* Revision 1.2"
@ -156,6 +158,9 @@ struct usb_cdc_notification {
uint16_t wLength;
} __attribute__((packed));
int cdc_connected();
void cdc_set_connected(int is_connected);
#endif
/**@}*/

View File

@ -41,6 +41,9 @@ int main(int argc, char **argv)
while (1)
{
usb_poll();
if (cdc_connected()) {
tester_poll();
}
}
return 0;
}

5
sw/src/tester.c Normal file
View File

@ -0,0 +1,5 @@
#include <tester.h>
void tester_poll(void) {
return;
}

13
sw/src/usb-cdc.c Normal file
View File

@ -0,0 +1,13 @@
#include <usb-cdc.h>
static int connected = 0;
int cdc_connected(void)
{
return connected;
}
void cdc_set_connected(int is_connected)
{
connected = is_connected;
}

View File

@ -3,6 +3,7 @@
#include <usb.h>
#include <usb-desc.h>
#include <usb-cdc.h>
static uint8_t reply_buffer[8];
static uint8_t usb_configuration = 0;
@ -15,6 +16,14 @@ void usb_setup(const struct usb_setup_request *setup)
switch (setup->wRequestAndType)
{
case 0x2021: // Set Line Coding
break;
case 0x2221: // Set control line state
cdc_set_connected(setup->wValue & 1); /* Check RTS bit */
break;
case 0x0500: // SET_ADDRESS
case 0x0b01: // SET_INTERFACE
break;