freemyipod r24 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r23‎ | r24 | r25 >
Date:03:44, 5 August 2010
Author:cmwslw
Status:new
Tags:
Comment:
Added I2C and accelerometer support.
Modified paths:
  • /embios/branches/4g_compat/SOURCES (modified) (history)
  • /embios/branches/4g_compat/gcc_extensions.h (added) (history)
  • /embios/branches/4g_compat/lcdconsole.c (modified) (history)
  • /embios/branches/4g_compat/snprintf.h (modified) (history)
  • /embios/branches/4g_compat/target/ipodnano2g/i2c.S (modified) (history)
  • /embios/branches/4g_compat/target/ipodnano4g/accel.c (added) (history)
  • /embios/branches/4g_compat/target/ipodnano4g/accel.h (added) (history)
  • /embios/branches/4g_compat/target/ipodnano4g/i2c.S (added) (history)
  • /embios/branches/4g_compat/target/ipodnano4g/i2c.h (added) (history)

Diff [purge]

Index: embios/branches/4g_compat/SOURCES
@@ -10,6 +10,8 @@
1111 target/ipodnano4g/mmu.c
1212 target/ipodnano4g/lcd.c
1313 target/ipodnano4g/storage.c
 14+target/ipodnano4g/i2c.S
 15+target/ipodnano4g/accel.c
1416 #endif
1517
1618 init.c
Index: embios/branches/4g_compat/target/ipodnano2g/i2c.S
@@ -95,7 +95,7 @@
9696 bl i2cwait
9797 ldr r0, [sp]
9898 orr r0, r0, #1
99 - str r1, [r12,#0x0c]
 99+ str r0, [r12,#0x0c]
100100 mov r0, #0xb0
101101 str r0, [r12,#0x04]
102102 str r4, [r12]
Index: embios/branches/4g_compat/target/ipodnano4g/i2c.h
@@ -0,0 +1,37 @@
 2+//
 3+//
 4+// Copyright 2010 TheSeven
 5+//
 6+//
 7+// This file is part of emBIOS.
 8+//
 9+// emBIOS is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emBIOS is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#ifndef __I2C_H__
 26+#define __I2C_H__
 27+
 28+
 29+#include "global.h"
 30+
 31+
 32+extern void i2csend(uint32_t device, uint32_t address, void* data, uint32_t length);
 33+extern void i2crecv(uint32_t device, uint32_t address, void* data, uint32_t length);
 34+extern void i2csendbyte(uint32_t device, uint32_t address, uint32_t data);
 35+extern uint32_t i2crecvbyte(uint32_t device, uint32_t address);
 36+
 37+
 38+#endif
Index: embios/branches/4g_compat/target/ipodnano4g/accel.c
@@ -0,0 +1,36 @@
 2+//
 3+//
 4+// Copyright 2010 TheSeven
 5+//
 6+//
 7+// This file is part of emBIOS.
 8+//
 9+// emBIOS is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emBIOS is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#include "global.h"
 26+#include "i2c.h"
 27+
 28+uint32_t accel_get_axis(uint8_t axis)
 29+{
 30+ uint8_t address = 0x29 + 2 * axis;
 31+ return i2crecvbyte(0x3a, address);
 32+}
 33+
 34+float accel_get_axis_in_gs(uint8_t axis)
 35+{
 36+ return accel_get_axis(axis) / 16;
 37+}
Index: embios/branches/4g_compat/target/ipodnano4g/accel.h
@@ -0,0 +1,32 @@
 2+//
 3+//
 4+// Copyright 2010 TheSeven
 5+//
 6+//
 7+// This file is part of emBIOS.
 8+//
 9+// emBIOS is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emBIOS is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#ifndef __ACCEL_H__
 26+#define __ACCEL_H__
 27+
 28+#include "global.h"
 29+
 30+uint8_t accel_get_axis(uint8_t axis);
 31+uint8_t accel_get_axis_in_gs(uint8_t axis);
 32+
 33+#endif
Index: embios/branches/4g_compat/target/ipodnano4g/i2c.S
@@ -0,0 +1,135 @@
 2+@
 3+@
 4+@ Copyright 2010 TheSeven
 5+@
 6+@
 7+@ This file is part of emBIOS.
 8+@
 9+@ emBIOS is free software: you can redistribute it and/or
 10+@ modify it under the terms of the GNU General Public License as
 11+@ published by the Free Software Foundation, either version 2 of the
 12+@ License, or (at your option) any later version.
 13+@
 14+@ emBIOS is distributed in the hope that it will be useful,
 15+@ but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+@ See the GNU General Public License for more details.
 18+@
 19+@ You should have received a copy of the GNU General Public License
 20+@ along with emBIOS. If not, see <http://www.gnu.org/licenses/>.
 21+@
 22+@
 23+
 24+
 25+.section .icode.i2csend, "ax", %progbits
 26+.align 2
 27+.global i2csendbyte
 28+.global i2csend
 29+.type i2csendbyte, %function
 30+.type i2csend, %function
 31+i2csendbyte:
 32+ mov r3, #0
 33+@fallthrough
 34+
 35+i2csend:
 36+ stmfd sp!, {r4,lr}
 37+ mov r12, #0x3C000000
 38+ add r12, r12, #0x00600000
 39+ mov r4, #0
 40+ str r4, [r12,#0x08]
 41+ str r0, [r12,#0x0c]
 42+ mov r4, #0xf0
 43+ str r4, [r12,#0x04]
 44+ mov r4, #0xf3
 45+ str r4, [r12]
 46+ bl i2cwait
 47+ str r1, [r12,#0x0c]
 48+ str r4, [r12]
 49+ bl i2cwait
 50+ movs r3, r3
 51+ moveq r0, r2
 52+i2csend_write:
 53+ ldrne r0, [r2], #1
 54+ str r0, [r12,#0x0c]
 55+ str r4, [r12]
 56+ bl i2cwait
 57+ subs r3, r3, #1
 58+ bhi i2csend_write
 59+ mov r0, #0xd0
 60+ str r0, [r12,#0x04]
 61+ str r4, [r12]
 62+i2csend_wait:
 63+ ldr r0, [r12,#0x04]
 64+ tst r0, #0x20
 65+ bne i2csend_wait
 66+ ldmfd sp!, {r4,pc}
 67+.size i2csendbyte, .-i2csendbyte
 68+.size i2csend, .-i2csend
 69+
 70+
 71+.section .icode.i2crecv, "ax", %progbits
 72+.align 2
 73+.global i2crecvbyte
 74+.global i2crecv
 75+.type i2crecvbyte, %function
 76+.type i2crecv, %function
 77+i2crecvbyte:
 78+ mov r2, #0
 79+ mov r3, #1
 80+@fallthrough
 81+
 82+i2crecv:
 83+ stmfd sp!, {r0,r4,lr} @ R0 = slave id, R1 = I2C address, R2 = data, R3 = length
 84+ mov r12, #0x3C000000 @ R12 = I2C base address
 85+ add r12, r12, #0x00600000 @ DIFF!! something needs to be done about the different busses
 86+ mov r4, #0
 87+ str r4, [r12,#0x08] @ store 0 to the i2c address + 0x8
 88+ str r0, [r12,#0x0c] @ write the slave id to the i2c handler
 89+ mov r4, #0xf0
 90+ str r4, [r12,#0x04] @ write 0xF0 to the i2c handler (idk why)
 91+ mov r4, #0xf3
 92+ str r4, [r12] @ write 0xF3 to the i2c handler (apparently a finished signal)
 93+ bl i2cwait
 94+ str r1, [r12,#0x0c] @ write the i2c address to the i2c handler
 95+ str r4, [r12] @ write 0xF3 to the i2c handler (apparently a finished signal)
 96+ bl i2cwait
 97+ ldr r0, [sp] @ DIFF!! why is it stack pointer here?
 98+ orr r0, r0, #1 @ find the least significant bit of the slave id
 99+ str r0, [r12,#0x0c] @ write it to the i2c handler
 100+ mov r0, #0xb0
 101+ str r0, [r12,#0x04] @ write 0xB0 to the i2c handler (idk why)
 102+ str r4, [r12] @ write 0xF3 to the i2c handler (apparently a finished signal)
 103+ bl i2cwait
 104+i2crecv_read:
 105+ subs r3, r3, #1 @ decrement the bytes left
 106+ moveq r4, #0x73 @ set R6 to 0x73 if the bytes left is now 0
 107+ str r4, [r12]
 108+ bl i2cwait
 109+ ldr r0, [r12,#0x0c] @ read a byte into R0
 110+ movs r2, r2
 111+ strne r0, [r2], #1 @ write it to our buffer
 112+ movs r3, r3
 113+ bne i2crecv_read @ repeat if there are still bytes left
 114+ mov r1, #0x90
 115+ str r1, [r12,#0x04] @ write 0x90 to the i2c handler
 116+ mov r1, #0xf3
 117+ str r1, [r12] @ write 0xF3 to the i2c handler (apparently a finished signal)
 118+i2crecv_wait:
 119+ ldr r1, [r12,#0x04]
 120+ tst r1, #0x20
 121+ bne i2crecv_wait @ wait until [R12,#0x04] does not equal 0x20
 122+ ldmfd sp!, {r1,r4,pc}
 123+.size i2crecvbyte, .-i2crecvbyte
 124+.size i2crecv, .-i2crecv
 125+
 126+
 127+.section .icode.i2cwait, "ax", %progbits
 128+.align 2
 129+.global i2cwait
 130+.type i2cwait, %function
 131+i2cwait:
 132+ ldr r0, [r12]
 133+ tst r0, #0x10
 134+ beq i2cwait
 135+ mov pc, lr
 136+.size i2cwait, .-i2cwait
Index: embios/branches/4g_compat/snprintf.h
@@ -27,8 +27,14 @@
2828
2929 #define __need___va_list
3030 #include <stdarg.h>
 31+#include "gcc_extensions.h"
3132 #include "global.h"
3233
 34+#ifdef __GNUC__
 35+#define __VALIST __gnuc_va_list
 36+#else
 37+#define __VALIST char*
 38+#endif
3339
3440 int vsnprintf (char *buf, size_t size, const char *fmt, __VALIST ap);
3541
Index: embios/branches/4g_compat/gcc_extensions.h
@@ -0,0 +1,46 @@
 2+/***************************************************************************
 3+ * __________ __ ___.
 4+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
 5+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
 6+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
 7+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
 8+ * \/ \/ \/ \/ \/
 9+ *
 10+ * Copyright © 2010 Rafaël Carré
 11+ *
 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.
 16+ *
 17+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 18+ * KIND, either express or implied.
 19+ *
 20+ ****************************************************************************/
 21+
 22+#ifndef _GCC_EXTENSIONS_H_
 23+#define _GCC_EXTENSIONS_H_
 24+
 25+/* Support for some GCC extensions */
 26+
 27+/* Compile time check of format for printf/scanf like functions */
 28+#ifdef __GNUC__
 29+#define ATTRIBUTE_PRINTF(fmt, arg1) __attribute__( ( format( printf, fmt, arg1 ) ) )
 30+#define ATTRIBUTE_SCANF(fmt, arg1) __attribute__( ( format( scanf, fmt, arg1 ) ) )
 31+#else
 32+#define ATTRIBUTE_PRINTF(fmt, arg1)
 33+#define ATTRIBUTE_SCANF(fmt, arg1)
 34+#endif
 35+
 36+
 37+/* Use to give gcc hints on which branch is most likely taken */
 38+#if defined(__GNUC__) && __GNUC__ >= 3
 39+#define LIKELY(x) __builtin_expect(!!(x), 1)
 40+#define UNLIKELY(x) __builtin_expect(!!(x), 0)
 41+#else
 42+#define LIKELY(x) (x)
 43+#define UNLIKELY(x) (x)
 44+#endif
 45+
 46+
 47+#endif /* _GCC_EXTENSIONS_H_ */
Index: embios/branches/4g_compat/lcdconsole.c
@@ -49,7 +49,11 @@
5050
5151 void lcdconsole_putc(char string, int fgcolor, int bgcolor)
5252 {
53 - if (string == '\r') return;
 53+ if (string == '\r')
 54+ {
 55+ current_col = 0;
 56+ return;
 57+ }
5458 current_col++;
5559 if (string == '\n')
5660 {