1 /* $OpenBSD: uslhcomreg.h,v 1.2 2015/01/22 14:33:01 krw Exp $ */ 2 3 /* 4 * Copyright (c) 2015 SASANO Takayoshi <uaa@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #define USLHCOM_TX_HEADER_SIZE sizeof(u_char) 20 21 #define SET_TRANSMIT_DATA(x) (x) 22 #define GET_RECEIVE_DATA(x) (x) 23 24 #define SET_DEVICE_RESET 0x40 25 #define GET_SET_UART_ENABLE 0x41 26 #define GET_UART_STATUS 0x42 27 #define SET_CLEAR_FIFOS 0x43 28 #define GET_GPIO_STATE 0x44 29 #define SET_GPIO_STATE 0x45 30 #define GET_VERSION 0x46 31 #define GET_SET_OTP_LOCK_BYTE 0x47 32 33 #define GET_SET_UART_CONFIG 0x50 34 #define SET_TRANSMIT_LINE_BREAK 0x51 35 #define SET_STOP_LINE_BREAK 0x52 36 37 38 /* SET_DEVICE_RESET */ 39 #define DEVICE_RESET_VALUE 0x00 40 41 /* GET_SET_UART_ENABLE */ 42 #define UART_DISABLE 0x00 43 #define UART_ENABLE 0x01 44 45 /* GET_UART_STATUS */ 46 struct uslhcom_uart_status { 47 u_char tx_fifo[2]; /* (big endian) */ 48 u_char rx_fifo[2]; /* (big endian) */ 49 u_char error_status; 50 u_char break_status; 51 } __packed; 52 53 #define ERROR_STATUS_PARITY 0x01 54 #define ERROR_STATUS_OVERRUN 0x02 55 #define BREAK_STATUS 0x01 56 57 /* SET_CLEAR_FIFO */ 58 #define CLEAR_TX_FIFO 0x01 59 #define CLEAR_RX_FIFO 0x02 60 61 /* GET_VERSION */ 62 struct uslhcom_version_info { 63 u_char product_id; 64 u_char product_revision; 65 } __packed; 66 67 /* GET_SET_UART_CONFIG */ 68 struct uslhcom_uart_config { 69 u_char baud_rate[4]; /* (big endian) */ 70 u_char parity; 71 u_char data_control; 72 u_char data_bits; 73 u_char stop_bits; 74 } __packed; 75 76 /* 77 * Silicon Labs CP2110/4 Application Note (AN434) Rev 0.4 says that 78 * valid baud rate is 300bps to 500,000bps. 79 * But HidUartSample of CP2110 SDK accepts 50bps to 2,000,000bps. 80 */ 81 #define UART_CONFIG_BAUD_RATE_MIN 50 82 #define UART_CONFIG_BAUD_RATE_MAX 2000000 83 84 #define UART_CONFIG_PARITY_NONE 0x00 85 #define UART_CONFIG_PARITY_EVEN 0x01 86 #define UART_CONFIG_PARITY_ODD 0x02 87 #define UART_CONFIG_PARITY_MARK 0x03 88 #define UART_CONFIG_PARITY_SPACE 0x04 89 90 #define UART_CONFIG_DATA_CONTROL_NONE 0x00 91 #define UART_CONFIG_DATA_CONTROL_HARD 0x01 92 93 /* 94 * AN434 Rev 0.4 describes setting 0x05 ... 0x08 to configure data bits. 95 * But actually it requires different values. 96 */ 97 #define UART_CONFIG_DATA_BITS_5 0x00 98 #define UART_CONFIG_DATA_BITS_6 0x01 99 #define UART_CONFIG_DATA_BITS_7 0x02 100 #define UART_CONFIG_DATA_BITS_8 0x03 101 102 #define UART_CONFIG_STOP_BITS_1 0x00 103 #define UART_CONFIG_STOP_BITS_2 0x01 104