You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

6 years ago
6 years ago
  1. /* gc_n64_usb : Gamecube or N64 controller to USB firmware
  2. Copyright (C) 2007-2016 Raphael Assenat <raph@raphnet.net>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdio.h>
  15. #include <avr/io.h>
  16. #include "usart1.h"
  17. #ifdef UART1_STDOUT
  18. static int uart1_putchar(char c, FILE *stream)
  19. {
  20. usart1_send(&c, 1);
  21. return 0;
  22. }
  23. static FILE mystdout = FDEV_SETUP_STREAM(uart1_putchar, NULL,
  24. _FDEV_SETUP_WRITE);
  25. #endif
  26. void usart1_send(void *data, int len)
  27. {
  28. while (!(UCSR1A & (1<<UDRE1)));
  29. UDR1 = *((unsigned char*)data);
  30. data++;
  31. }
  32. void usart1_init(void)
  33. {
  34. UCSR1B = (1<<TXEN1);
  35. UCSR1C = (1<<UCSZ11) | (1<<UCSZ10);
  36. #ifdef UCSR1D
  37. UCSR1D = 0;
  38. #endif
  39. UBRR1H = 0;
  40. #if F_CPU==8000000L
  41. UBRR1L = 8; // 57600 at 3.5% error at 8MHz
  42. #elif F_CPU==16000000L
  43. UBRR1L = 16; // 57600 at 2.1% error at 16MHz
  44. #else
  45. #error Unsupported clock
  46. #endif
  47. #ifdef UART1_STDOUT
  48. stdout = &mystdout;
  49. #endif
  50. }