freemyipod r117 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r116‎ | r117 | r118 >
Date:21:44, 12 August 2010
Author:theseven
Status:new
Tags:
Comment:
Add backlight driver
Modified paths:
  • /embios/trunk/SOURCES (modified) (history)
  • /embios/trunk/backlight.h (added) (history)
  • /embios/trunk/export/syscallapi.h (modified) (history)
  • /embios/trunk/export/syscallwrappers.h (modified) (history)
  • /embios/trunk/syscallapi.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/backlight.c (added) (history)
  • /embios/trunk/target/ipodnano2g/target.h (modified) (history)
  • /embios/trunk/target/ipodnano4g/backlight.c (modified) (history)
  • /embios/trunk/target/ipodnano4g/backlight.h (deleted) (history)
  • /embios/trunk/target/ipodnano4g/target.h (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodnano2g/backlight.c
@@ -0,0 +1,42 @@
 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+#include "backlight.h"
 28+
 29+
 30+void backlight_on(bool on)
 31+{
 32+ i2c_sendbyte(0, 0xe6, 0x29, on ? 1 : 0);
 33+}
 34+
 35+void backlight_set_fade(uint8_t fade)
 36+{
 37+ i2c_sendbyte(0, 0xe6, 0x2b, fade);
 38+}
 39+
 40+void backlight_set_brightness(uint8_t brightness)
 41+{
 42+ i2c_sendbyte(0, 0xe6, 0x28, (46 * (brightness & 0xff)) >> 8);
 43+}
Index: embios/trunk/target/ipodnano2g/target.h
@@ -46,6 +46,8 @@
4747 #define LCD_FORMAT rgb565
4848 #define LCD_BYTESPERPIXEL 2
4949
 50+#define HAVE_BACKLIGHT
 51+
5052 #define HAVE_I2C
5153
5254 #define HAVE_BOOTFLASH
Index: embios/trunk/target/ipodnano4g/backlight.h
@@ -1,34 +0,0 @@
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 __BACKLIGHT_H__
26 -#define __BACKLIGHT_H__
27 -
28 -#include "global.h"
29 -
30 -// fade is only used on the 2G but keep it here for a common API (use anything)
31 -void backlight_set(double brightness, uint8_t fade);
32 -void backlight_on(uint8_t fade);
33 -void backlight_off(uint8_t fade);
34 -
35 -#endif
Index: embios/trunk/target/ipodnano4g/backlight.c
@@ -23,19 +23,23 @@
2424
2525 #include "global.h"
2626 #include "i2c.h"
 27+#include "backlight.h"
2728
28 -void backlight_set(uint8_t brightness, uint8_t fade)
 29+
 30+static bool backlight_fade;
 31+
 32+
 33+void backlight_on(bool on)
2934 {
30 - i2csendbyte(0xe6, 0x30, brightness);
31 - i2csendbyte(0xe6, 0x31, 3);
 35+ i2c_sendbyte(0, 0xe6, 0x31, (backlight_fade ? 2 : 0) + (on ? 1 : 0));
3236 }
3337
34 -void backlight_on(uint8_t fade)
 38+void backlight_set_fade(uint8_t fade)
3539 {
36 - backlight_set(255, 32);
 40+ backlight_fade = fade;
3741 }
3842
39 -void backlight_off(uint8_t fade)
 43+void backlight_set_brightness(uint8_t brightness)
4044 {
41 - i2csendbyte(0xe6, 0x31, 2);
 45+ i2c_sendbyte(0, 0xe6, 0x30, (250 * (brightness & 0xff)) >> 8);
4246 }
Index: embios/trunk/target/ipodnano4g/target.h
@@ -46,6 +46,8 @@
4747 #define LCD_FORMAT rgb565
4848 #define LCD_BYTESPERPIXEL 2
4949
 50+#define HAVE_BACKLIGHT
 51+
5052 #define HAVE_I2C
5153
5254 //#define HAVE_STORAGE
Index: embios/trunk/export/syscallwrappers.h
@@ -152,6 +152,9 @@
153153 #define strrchr(args...) __embios_syscall->strrchr(args)
154154 #define strstr(args...) __embios_syscall->strstr(args)
155155 #define strtok_r(args...) __embios_syscall->strtok_r(args)
 156+#define backlight_on(args...) __embios_syscall->backlight_on(args)
 157+#define backlight_set_fade(args...) __embios_syscall->backlight_set_fade(args)
 158+#define backlight_set_brightness(args...) __embios_syscall->backlight_set_brightness(args)
156159
157160
158161 #endif
Index: embios/trunk/export/syscallapi.h
@@ -45,6 +45,7 @@
4646 #include "../nand.h"
4747 #include "../power.h"
4848 #include "../execimage.h"
 49+#include "../backlight.h"
4950 #include "../libc/include/string.h"
5051 #include "../libc/include/stdlib.h"
5152 #include "../libc/include/stdio.h"
@@ -183,6 +184,9 @@
184185 typeof(strrchr) *strrchr;
185186 typeof(strstr) *strstr;
186187 typeof(strtok_r) *strtok_r;
 188+ typeof(backlight_on) *backlight_on;
 189+ typeof(backlight_set_fade) *backlight_set_fade;
 190+ typeof(backlight_set_brightness) *backlight_set_brightness;
187191 };
188192
189193
Index: embios/trunk/backlight.h
@@ -0,0 +1,33 @@
 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 __BACKLIGHT_H__
 26+#define __BACKLIGHT_H__
 27+
 28+#include "global.h"
 29+
 30+void backlight_on(bool on);
 31+void backlight_set_fade(uint8_t fade);
 32+void backlight_set_brightness(uint8_t brightness);
 33+
 34+#endif
Index: embios/trunk/SOURCES
@@ -13,6 +13,7 @@
1414 target/ipodnano2g/storage_nand.c
1515 target/ipodnano2g/clockgates.c
1616 target/ipodnano2g/bootflash.c
 17+target/ipodnano2g/backlight.c
1718 usb/synopsysotg.c
1819 #endif
1920
Index: embios/trunk/syscallapi.c
@@ -42,6 +42,7 @@
4343 #include "nand.h"
4444 #include "power.h"
4545 #include "execimage.h"
 46+#include "backlight.h"
4647 #include "libc/include/string.h"
4748 #include "libc/include/stdlib.h"
4849 #include "libc/include/stdio.h"
@@ -158,6 +159,11 @@
159160 .lcd_get_height = lcd_get_height,
160161 .lcd_get_bytes_per_pixel = lcd_get_bytes_per_pixel,
161162 #endif
 163+#ifdef HAVE_BACKLIGHT
 164+ .backlight_on = backlight_on,
 165+ .backlight_set_fade = backlight_set_fade,
 166+ .backlight_set_brightness = backlight_set_brightness,
 167+#endif
162168 #ifdef HAVE_BOOTFLASH
163169 .bootflash_filesize = bootflash_filesize,
164170 .bootflash_attributes = bootflash_attributes,