From ecaa40166000e3d6b49542d42804127c0a6079e2 Mon Sep 17 00:00:00 2001 From: andypotter Date: Mon, 15 Apr 2013 20:09:39 +0100 Subject: Add Serial Port 1 support for iPod Photo/Color/4G/Mini2G Based on FS#9920 by Ryan Press with changes to selection logic so that it works on my iPod Photo. Should also work on iPod Color/4G and Mini2G. Moved all target specific code from firmware/drivers/serial.c into new file firmware/target/arm/pp/uart-pp.c in the same manner as other target specific uart code. Update to fix build error on ipodmini2g by adding defines in config file. Removed unwanted whitespace Tested on iPod Photo. Change-Id: Ia5539563966198e06372d70b5adf2ef78882f863 Reviewed-on: http://gerrit.rockbox.org/455 Reviewed-by: andypotter Tested-by: andypotter Reviewed-by: Marcin Bukat --- firmware/drivers/serial.c | 172 ---------------------------------------------- 1 file changed, 172 deletions(-) (limited to 'firmware/drivers/serial.c') diff --git a/firmware/drivers/serial.c b/firmware/drivers/serial.c index a46342389d..0fab570fdc 100644 --- a/firmware/drivers/serial.c +++ b/firmware/drivers/serial.c @@ -21,179 +21,7 @@ #include #include #include -#include "button.h" -#include "config.h" -#include "cpu.h" -#include "system.h" -#include "kernel.h" -#include "lcd.h" #include "serial.h" -#include "iap.h" - -#if defined(IPOD_ACCESSORY_PROTOCOL) -static int autobaud = 0; - -static void set_bitrate(unsigned int rate) -{ - unsigned int divisor; - - divisor = 24000000L / rate / 16; - SER0_LCR = 0x80; /* Divisor latch enable */ - SER0_DLL = (divisor >> 0) & 0xFF; - SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */ -} - -void serial_setup (void) -{ - int tmp; - -#if defined(IPOD_COLOR) || defined(IPOD_4G) - /* Route the Tx/Rx pins. 4G Ipod??? */ - outl(0x70000018, inl(0x70000018) & ~0xc00); -#elif defined(IPOD_NANO) || defined(IPOD_VIDEO) - /* Route the Tx/Rx pins. 5G Ipod */ - (*(volatile unsigned long *)(0x7000008C)) &= ~0x0C; - GPO32_ENABLE &= ~0x0C; -#endif - - DEV_EN = DEV_EN | DEV_SER0; - CPU_HI_INT_DIS = SER0_MASK; - - DEV_RS |= DEV_SER0; - sleep(1); - DEV_RS &= ~DEV_SER0; - - SER0_LCR = 0x80; /* Divisor latch enable */ - SER0_DLM = 0x00; - SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */ - SER0_IER = 0x01; - - SER0_FCR = 0x07; /* Tx+Rx FIFO reset and FIFO enable */ - - CPU_INT_EN |= HI_MASK; - CPU_HI_INT_EN |= SER0_MASK; - tmp = SER0_RBR; - - serial_bitrate(0); -} - -void serial_bitrate(int rate) -{ - if(rate == 0) - { - autobaud = 2; - set_bitrate(115200); - } - else - { - autobaud = 0; - set_bitrate(rate); - } -} - -int tx_rdy(void) -{ - if((SER0_LSR & 0x20)) - return 1; - else - return 0; -} - -static int rx_rdy(void) -{ - if((SER0_LSR & 0x1)) - return 1; - else - return 0; -} - -void tx_writec(unsigned char c) -{ - SER0_THR =(int) c; -} - -static unsigned char rx_readc(void) -{ - return (SER0_RBR & 0xFF); -} - -void SERIAL0(void) -{ - static int badbaud = 0; - static bool newpkt = true; - char temp; - - while(rx_rdy()) - { - temp = rx_readc(); - if (newpkt && autobaud > 0) - { - if (autobaud == 1) - { - switch (temp) - { - case 0xFF: - case 0x55: - break; - case 0xFC: - set_bitrate(19200); - temp = 0xFF; - break; - case 0xE0: - set_bitrate(9600); - temp = 0xFF; - break; - default: - badbaud++; - if (badbaud >= 6) /* Switch baud detection mode */ - { - autobaud = 2; - set_bitrate(115200); - badbaud = 0; - } else { - set_bitrate(57600); - } - continue; - } - } else { - switch (temp) - { - case 0xFF: - case 0x55: - break; - case 0xFE: - set_bitrate(57600); - temp = 0xFF; - break; - case 0xFC: - set_bitrate(38400); - temp = 0xFF; - break; - case 0xE0: - set_bitrate(19200); - temp = 0xFF; - break; - default: - badbaud++; - if (badbaud >= 6) /* Switch baud detection */ - { - autobaud = 1; - set_bitrate(57600); - badbaud = 0; - } else { - set_bitrate(115200); - } - continue; - } - } - } - bool pkt = iap_getc(temp); - if(newpkt && !pkt) - autobaud = 0; /* Found good baud */ - newpkt = pkt; - } -} -#endif void dprintf(const char * str, ... ) { -- cgit v1.2.3