Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / firmware / target / arm / tcc77x / iaudio7 / ata2501.c
blobf7526b2b9ab44a086765b39a61a2357755abf924
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 Vitja Makarov
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include "system.h"
24 #include "cpu.h"
25 #include "button.h"
27 #include "ata2501.h"
29 #define STB (1<<5)
30 #define SDATA (1<<4)
31 #define RESET (1<<6)
32 #define SIFMD (1<<7)
33 #define STB_DELAY 200
35 static inline void ndelay(unsigned long nsecs)
37 nsecs /= 8;
38 while (nsecs)
39 nsecs--;
43 TODO: sensitivity
45 void ata2501_init(void)
47 GPIOD_DIR |= (RESET | STB | SIFMD | (1 << 8) | (1 << 9));
48 GPIOD_DIR &= ~SDATA;
50 GPIOD &= ~STB;
51 GPIOD |= (1 << 8) | SIFMD | (1 << 9);
53 GPIOD &= ~RESET;
54 ndelay(1000);
55 GPIOD |= RESET;
58 unsigned short ata2501_read(void)
60 unsigned short ret = 0;
61 int i;
63 for (i = 0; i < 12; i++) {
64 GPIOD |= STB;
65 ndelay(100);
66 ret <<= 1;
67 if (GPIOD & SDATA)
68 ret |= 1;
69 GPIOD &= ~STB;
70 ndelay(100);
73 return ret;
76 //#define ATA2501_TEST
77 #ifdef ATA2501_TEST
78 #include "lcd.h"
80 static
81 void bits(char *str, unsigned short val)
83 int i;
85 for (i = 0; i < 12; i++)
86 str[i] = (val & (1 << i)) ? '1' : '0';
87 str[i] = 0;
90 void ata2501_test(void)
92 char buf[100];
93 ata2501_init();
95 while (1) {
96 unsigned short data;
97 int line = 0;
99 data = ata2501_read();
100 lcd_clear_display();
101 lcd_puts(0, line++, "ATA2501 test");
103 bits(buf, data);
104 lcd_puts(0, line++, buf);
106 lcd_update();
107 sleep(HZ/10);
110 #endif