Revision 1143
Added usb_puth* to serial.c/serial.h
trunk/code/lib/include/libdragonfly/serial.h | ||
---|---|---|
95 | 95 |
int usb_puts(char *s); |
96 | 96 |
/** @brief Print an integer to USB **/ |
97 | 97 |
int usb_puti(int value); |
98 |
/** @brief Determine a hexadecimal digit **/ |
|
99 |
uint8_t hex_digit (uint8_t value); |
|
100 |
/** @brief Print a fixed width hexadecimal representation to USB **/ |
|
101 |
void usb_puth16 (uint16_t value); |
|
102 |
/** @brief Print a fixed width hexadecimal representation to USB **/ |
|
103 |
void usb_puth8(uint8_t value); |
|
104 |
/** @brief Alias for usb_puth16 **/ |
|
105 |
static inline void usb_puth (uint16_t value) { usb_puth16 (value); }; |
|
98 | 106 |
|
107 |
|
|
99 | 108 |
/** @} **/ //end addtogroup |
100 | 109 |
|
101 | 110 |
/** |
... | ... | |
124 | 133 |
/** @brief Read a character from the XBee without blocking **/ |
125 | 134 |
int xbee_getc_nb(char *c); |
126 | 135 |
|
136 |
|
|
137 |
|
|
127 | 138 |
/** @} **/ //end addtogroup |
128 | 139 |
|
129 | 140 |
#endif |
trunk/code/projects/libdragonfly/serial.c | ||
---|---|---|
276 | 276 |
|
277 | 277 |
return 0; |
278 | 278 |
} |
279 |
|
|
280 |
/** |
|
281 |
* Determines a hexadecimal digit in ASCII code. |
|
282 |
* |
|
283 |
* @param value the value of the digit (0<=value<=15) |
|
284 |
* |
|
285 |
* @return the hexadecimal digit in ASCII code, or '?' |
|
286 |
* if the input is invalid. |
|
287 |
**/ |
|
288 |
uint8_t hex_digit (uint8_t value) |
|
289 |
{ |
|
290 |
if (value>15) return '?'; |
|
291 |
// Postcondition: 0<=x<=15 |
|
292 |
|
|
293 |
return "0123456789ABCDEF"[value]; |
|
294 |
} |
|
295 |
|
|
296 |
/** |
|
297 |
* Prints a fixed width hexadecimal representation of an unsigned |
|
298 |
* 16 bit integer in ASCII code to USB. |
|
299 |
* usb_init must be called before this function can be used. |
|
300 |
* |
|
301 |
* @param value the value to print |
|
302 |
* |
|
303 |
* @see usb_init, usb_puti, usb_puts, usb_puth8, hex_digit |
|
304 |
**/ |
|
305 |
void usb_puth16 (uint16_t value) |
|
306 |
{ |
|
307 |
usb_putc (hex_digit((value >>12)&0xF)); |
|
308 |
usb_putc (hex_digit((value >>8 )&0xF)); |
|
309 |
usb_putc (hex_digit((value >>4 )&0xF)); |
|
310 |
usb_putc (hex_digit( value &0xF)); |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 |
* Prints a fixed width hexadecimal representation of an unsigned |
|
315 |
* 8 bit integer in ASCII code to USB. |
|
316 |
* usb_init must be called before this function can be used. |
|
317 |
* |
|
318 |
* @param value the value to print |
|
319 |
* |
|
320 |
* @see usb_init, usb_puti, usb_puts, usb_puth16, hex_digit |
|
321 |
**/ |
|
322 |
void usb_puth8(uint8_t value) |
|
323 |
{ |
|
324 |
usb_putc (hex_digit ((value)>>4 &0xF)); |
|
325 |
usb_putc (hex_digit ( value &0xF)); |
|
326 |
} |
|
327 |
|
trunk/code/projects/libdragonfly/serial.h | ||
---|---|---|
95 | 95 |
int usb_puts(char *s); |
96 | 96 |
/** @brief Print an integer to USB **/ |
97 | 97 |
int usb_puti(int value); |
98 |
/** @brief Determine a hexadecimal digit **/ |
|
99 |
uint8_t hex_digit (uint8_t value); |
|
100 |
/** @brief Print a fixed width hexadecimal representation to USB **/ |
|
101 |
void usb_puth16 (uint16_t value); |
|
102 |
/** @brief Print a fixed width hexadecimal representation to USB **/ |
|
103 |
void usb_puth8(uint8_t value); |
|
104 |
/** @brief Alias for usb_puth16 **/ |
|
105 |
static inline void usb_puth (uint16_t value) { usb_puth16 (value); }; |
|
98 | 106 |
|
107 |
|
|
99 | 108 |
/** @} **/ //end addtogroup |
100 | 109 |
|
101 | 110 |
/** |
... | ... | |
124 | 133 |
/** @brief Read a character from the XBee without blocking **/ |
125 | 134 |
int xbee_getc_nb(char *c); |
126 | 135 |
|
136 |
|
|
137 |
|
|
127 | 138 |
/** @} **/ //end addtogroup |
128 | 139 |
|
129 | 140 |
#endif |
Also available in: Unified diff