xref: /btstack/port/archive/msp430f5229lp-cc2564b/firmware/hal_usb.c (revision 1664436fd643daf66517dc309e6cc72448e8a86d)
1*1664436fSMatthias Ringwald /**
2*1664436fSMatthias Ringwald  * @file  hal_usb.c
3*1664436fSMatthias Ringwald  *
4*1664436fSMatthias Ringwald  * Copyright 2008 Texas Instruments, Inc.
5*1664436fSMatthias Ringwald ***************************************************************************/
6*1664436fSMatthias Ringwald #include  <msp430.h>
7*1664436fSMatthias Ringwald #include "hal_usb.h"
8*1664436fSMatthias Ringwald 
9*1664436fSMatthias Ringwald /************************************************************************
10*1664436fSMatthias Ringwald  * @brief  Initializes the serial communications peripheral and GPIO ports
11*1664436fSMatthias Ringwald  *         to communicate with the TUSB3410.
12*1664436fSMatthias Ringwald  *
13*1664436fSMatthias Ringwald  * @param  none
14*1664436fSMatthias Ringwald  *
15*1664436fSMatthias Ringwald  * @return none
16*1664436fSMatthias Ringwald  **************************************************************************/
halUsbInit(void)17*1664436fSMatthias Ringwald void halUsbInit(void)
18*1664436fSMatthias Ringwald {
19*1664436fSMatthias Ringwald 
20*1664436fSMatthias Ringwald   USB_PORT_SEL |= USB_PIN_RXD + USB_PIN_TXD;
21*1664436fSMatthias Ringwald   USB_PORT_DIR |= USB_PIN_TXD;
22*1664436fSMatthias Ringwald   USB_PORT_DIR &= ~USB_PIN_RXD;
23*1664436fSMatthias Ringwald 
24*1664436fSMatthias Ringwald   UCA1CTL1 |= UCSWRST;                          //Reset State
25*1664436fSMatthias Ringwald   UCA1CTL0 = UCMODE_0;
26*1664436fSMatthias Ringwald 
27*1664436fSMatthias Ringwald   UCA1CTL0 &= ~UC7BIT;                      // 8bit char
28*1664436fSMatthias Ringwald   UCA1CTL1 |= UCSSEL_2;
29*1664436fSMatthias Ringwald #if 0
30*1664436fSMatthias Ringwald   // 57600 @ 16 Mhz
31*1664436fSMatthias Ringwald   UCA1BR0 = 16;
32*1664436fSMatthias Ringwald   UCA1BR1 = 1;
33*1664436fSMatthias Ringwald #else
34*1664436fSMatthias Ringwald   // 115200 @ 16 Mhz
35*1664436fSMatthias Ringwald   UCA1BR0 = 138;
36*1664436fSMatthias Ringwald   UCA1BR1 = 0;
37*1664436fSMatthias Ringwald #endif
38*1664436fSMatthias Ringwald   UCA1MCTL = 0xE;
39*1664436fSMatthias Ringwald   UCA1CTL1 &= ~UCSWRST;
40*1664436fSMatthias Ringwald }
41*1664436fSMatthias Ringwald 
42*1664436fSMatthias Ringwald /************************************************************************
43*1664436fSMatthias Ringwald  * @brief  Disables the serial communications peripheral and clears the GPIO
44*1664436fSMatthias Ringwald  *         settings used to communicate with the TUSB3410.
45*1664436fSMatthias Ringwald  *
46*1664436fSMatthias Ringwald  * @param  none
47*1664436fSMatthias Ringwald  *
48*1664436fSMatthias Ringwald  * @return none
49*1664436fSMatthias Ringwald  **************************************************************************/
halUsbShutDown(void)50*1664436fSMatthias Ringwald void halUsbShutDown(void)
51*1664436fSMatthias Ringwald {
52*1664436fSMatthias Ringwald   UCA1IE &= ~UCRXIE;
53*1664436fSMatthias Ringwald   UCA1CTL1 = UCSWRST;                          //Reset State
54*1664436fSMatthias Ringwald   USB_PORT_SEL &= ~( USB_PIN_RXD + USB_PIN_TXD );
55*1664436fSMatthias Ringwald   USB_PORT_DIR |= USB_PIN_TXD;
56*1664436fSMatthias Ringwald   USB_PORT_DIR |= USB_PIN_RXD;
57*1664436fSMatthias Ringwald   USB_PORT_OUT &= ~(USB_PIN_TXD + USB_PIN_RXD);
58*1664436fSMatthias Ringwald }
59*1664436fSMatthias Ringwald 
60*1664436fSMatthias Ringwald /************************************************************************
61*1664436fSMatthias Ringwald  * @brief  Sends a character over UART to the TUSB3410.
62*1664436fSMatthias Ringwald  *
63*1664436fSMatthias Ringwald  * @param  character The character to be sent.
64*1664436fSMatthias Ringwald  *
65*1664436fSMatthias Ringwald  * @return none
66*1664436fSMatthias Ringwald  **************************************************************************/
halUsbSendChar(char character)67*1664436fSMatthias Ringwald void halUsbSendChar(char character)
68*1664436fSMatthias Ringwald {
69*1664436fSMatthias Ringwald   while (!(UCA1IFG & UCTXIFG));
70*1664436fSMatthias Ringwald   UCA1TXBUF = character;
71*1664436fSMatthias Ringwald }
72*1664436fSMatthias Ringwald 
halUsbRecvChar(void)73*1664436fSMatthias Ringwald char halUsbRecvChar(void){
74*1664436fSMatthias Ringwald     while (!(UCA1IFG & UCRXIFG));
75*1664436fSMatthias Ringwald     return UCA1RXBUF;
76*1664436fSMatthias Ringwald }
77*1664436fSMatthias Ringwald 
78*1664436fSMatthias Ringwald /************************************************************************
79*1664436fSMatthias Ringwald  * @brief  Sends a string of characters to the TUSB3410
80*1664436fSMatthias Ringwald  *
81*1664436fSMatthias Ringwald  * @param  string[] The array of characters to be transmit to the TUSB3410.
82*1664436fSMatthias Ringwald  *
83*1664436fSMatthias Ringwald  * @param  length   The length of the string.
84*1664436fSMatthias Ringwald  *
85*1664436fSMatthias Ringwald  * @return none
86*1664436fSMatthias Ringwald  **************************************************************************/
halUsbSendString(char string[],unsigned char length)87*1664436fSMatthias Ringwald void halUsbSendString(char string[], unsigned char length)
88*1664436fSMatthias Ringwald {
89*1664436fSMatthias Ringwald   volatile unsigned char i;
90*1664436fSMatthias Ringwald   for (i=0; i < length; i++)
91*1664436fSMatthias Ringwald     halUsbSendChar(string[i]);
92*1664436fSMatthias Ringwald }
93*1664436fSMatthias Ringwald 
94*1664436fSMatthias Ringwald // provide putchar used by printf
putchar(int c)95*1664436fSMatthias Ringwald int putchar(int c){
96*1664436fSMatthias Ringwald     halUsbSendChar(c);
97*1664436fSMatthias Ringwald     return 1;
98*1664436fSMatthias Ringwald }