add: FPC connector skeleton usart. Not working but if will be a starting point for those who might want to help out with it.

This commit is contained in:
Chris 2018-07-30 09:54:44 +02:00
commit bacf8aff0f
8 changed files with 384 additions and 32 deletions

View file

@ -31,23 +31,30 @@
*/
#include "cmd.h"
// (iceman 2017) this method is not used anymore. uart_win32 /uart_posix is used instead
bool cmd_receive(UsbCommand* cmd) {
// Check if there is a usb packet available
if (!usb_poll_validate_length()) return false;
// Try to retrieve the available command frame
size_t rxlen = usb_read((byte_t*)cmd, sizeof(UsbCommand));
// (iceman) this check is wrong. Since USB can send packages which is not sizeof(usbcommand) 544 bytes.
// hence, I comment it out
// Check if the transfer was complete
//if (rxlen != sizeof(UsbCommand)) return false;
// Received command successfully
//return true;
return (rxlen);
// check if there is a FPC USART1 message?
/*
size_t fpc_rxlen = usart_read((uint8_t*)cmd, sizeof(UsbCommand));
if ( fpc_rxlen )
return true;
*/
// Check if there is a usb packet available
if (!usb_poll_validate_length()) return false;
// Try to retrieve the available command frame
usb_read((uint8_t*)cmd, sizeof(UsbCommand));
// (iceman) this check is wrong. Since USB can send packages which is not sizeof(usbcommand) 544 bytes.
// hence, I comment it out
// Check if the transfer was complete
//if (rxlen != sizeof(UsbCommand)) return false;
// Received command successfully
//return true;
return true;
}
bool cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void* data, size_t len) {
@ -56,7 +63,7 @@ bool cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void* d
// 0x00 the whole command.
for (size_t i=0; i < sizeof(UsbCommand); i++)
((byte_t*)&txcmd)[i] = 0x00;
((uint8_t*)&txcmd)[i] = 0x00;
// Compose the outgoing command frame
txcmd.cmd = cmd;
@ -68,13 +75,15 @@ bool cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void* d
if (data && len) {
len = MIN(len, USB_CMD_DATA_SIZE);
for (size_t i=0; i<len; i++) {
txcmd.d.asBytes[i] = ((byte_t*)data)[i];
txcmd.d.asBytes[i] = ((uint8_t*)data)[i];
}
}
//usart_send( (uint8_t*)&txcmd, sizeof(UsbCommand));
// Send frame and make sure all bytes are transmitted
if ( usb_write( (byte_t*)&txcmd, sizeof(UsbCommand)) != 0)
return false;
if ( usb_write( (uint8_t*)&txcmd, sizeof(UsbCommand)) != 0)
return false;
return true;
}