freemyipod r122 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r121‎ | r122 | r123 >
Date:15:18, 13 August 2010
Author:theseven
Status:new
Tags:
Comment:
Add progress bar API
Modified paths:
  • /embios/trunk/SOURCES (modified) (history)
  • /embios/trunk/export/syscallapi.h (modified) (history)
  • /embios/trunk/export/syscallwrappers.h (modified) (history)
  • /embios/trunk/lcd.h (modified) (history)
  • /embios/trunk/lcdconsole.c (modified) (history)
  • /embios/trunk/lcdconsole.h (modified) (history)
  • /embios/trunk/progressbar.c (added) (history)
  • /embios/trunk/progressbar.h (added) (history)
  • /embios/trunk/syscallapi.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/lcd.S (modified) (history)
  • /embios/trunk/target/ipodnano4g/lcd.S (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodnano2g/lcd.S
@@ -122,7 +122,7 @@
123123 add r3, r3, #1
124124 mul r2, r1, r3
125125 ldr r1, [sp,#0x18]
126 - cmp r1, #0x40000000
 126+ cmp r1, #-1
127127 bne displaylcd_dma
128128 displaylcd_pixel:
129129 ldr r0, [sp,#0x1c]
@@ -245,3 +245,22 @@
246246 bl lcdconsole_callback
247247 ldr pc, [sp], #4
248248 .size INT_DMA8, .-INT_DMA8
 249+
 250+.section .icode.lcd_translate_color, "ax", %progbits
 251+.align 2
 252+.global lcd_translate_color
 253+.type lcd_translate_color, %function
 254+lcd_translate_color:
 255+ cmp r0, #0xff
 256+ moveq r0, #-1
 257+ moveq pc, lr
 258+ cmp r0, #0
 259+ movne r0, #0xff000000
 260+ orrne r0, r0, #0xff0000
 261+ mov r2, r2,lsr#2
 262+ mov r1, r1,lsr#3
 263+ orr r0, r0, r3,lsr#3
 264+ orr r0, r0, r2,lsl#5
 265+ orr r0, r0, r1,lsl#11
 266+ mov pc, lr
 267+.size lcd_translate_color, .-lcd_translate_color
Index: embios/trunk/target/ipodnano4g/lcd.S
@@ -89,7 +89,7 @@
9090 add r3, r3, #1
9191 mul r2, r1, r3
9292 ldr r1, [sp,#0x10]
93 - cmp r1, #0x40000000
 93+ cmp r1, #-1
9494 bne displaylcd_framebuf
9595 displaylcd_color:
9696 ldr r0, [sp,#0x14]
@@ -144,3 +144,21 @@
145145 mov pc, lr
146146 .size displaylcd_safe, .-displaylcd_safe
147147
 148+.section .icode.lcd_translate_color, "ax", %progbits
 149+.align 2
 150+.global lcd_translate_color
 151+.type lcd_translate_color, %function
 152+lcd_translate_color:
 153+ cmp r0, #0xff
 154+ moveq r0, #-1
 155+ moveq pc, lr
 156+ cmp r0, #0
 157+ movne r0, #0xff000000
 158+ orrne r0, r0, #0xff0000
 159+ mov r2, r2,lsr#2
 160+ mov r1, r1,lsr#3
 161+ orr r0, r0, r3,lsr#3
 162+ orr r0, r0, r2,lsl#5
 163+ orr r0, r0, r1,lsl#11
 164+ mov pc, lr
 165+.size lcd_translate_color, .-lcd_translate_color
Index: embios/trunk/lcd.h
@@ -31,15 +31,16 @@
3232 #define LCD_FRAMEBUFSIZE (LCD_WIDTH * LCD_HEIGHT * LCD_BYTESPERPIXEL)
3333
3434
35 -void lcd_init();
36 -int lcd_get_width();
37 -int lcd_get_height();
38 -int lcd_get_bytes_per_pixel();
 35+void lcd_init() INITCODE_ATTR;
 36+int lcd_get_width() ICODE_ATTR;
 37+int lcd_get_height() ICODE_ATTR;
 38+int lcd_get_bytes_per_pixel() ICODE_ATTR;
 39+int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue) ICODE_ATTR;
3940 void displaylcd(unsigned int startx, unsigned int endx,
40 - unsigned int starty, unsigned int endy, void* data, int color);
41 -void displaylcd_sync();
42 -bool displaylcd_busy();
43 -bool displaylcd_safe();
 41+ unsigned int starty, unsigned int endy, void* data, int color) ICODE_ATTR;
 42+void displaylcd_sync() ICODE_ATTR;
 43+bool displaylcd_busy() ICODE_ATTR;
 44+bool displaylcd_safe() ICODE_ATTR;
4445
4546
4647 #endif
Index: embios/trunk/progressbar.c
@@ -0,0 +1,70 @@
 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 "progressbar.h"
 27+#include "lcd.h"
 28+
 29+
 30+static void progressbar_drawborderbg(struct progressbar_state* state)
 31+{
 32+ state->currentx = state->startx;
 33+ displaylcd(state->startx + 1, state->endx - 1, state->starty + 1, state->endy - 1,
 34+ (void*)-1, state->bgcolor);
 35+ displaylcd(state->startx, state->endx, state->starty, state->starty,
 36+ (void*)-1, state->bordercolor);
 37+ displaylcd(state->startx, state->endx, state->endy, state->endy,
 38+ (void*)-1, state->bordercolor);
 39+ displaylcd(state->startx, state->startx, state->starty + 1, state->endy - 1,
 40+ (void*)-1, state->bordercolor);
 41+ displaylcd(state->endx, state->endx, state->starty + 1, state->endy - 1,
 42+ (void*)-1, state->bordercolor);
 43+}
 44+
 45+void progressbar_init(struct progressbar_state* state, int startx, int endx, int starty, int endy,
 46+ int bordercolor, int bgcolor, int fgcolor, int min, int max)
 47+{
 48+ state->startx = startx;
 49+ state->endx = endx;
 50+ state->starty = starty;
 51+ state->endy = endy;
 52+ state->bordercolor = bordercolor;
 53+ state->bgcolor = bgcolor;
 54+ state->fgcolor = fgcolor;
 55+ state->min = min;
 56+ state->max = max;
 57+ progressbar_drawborderbg(state);
 58+}
 59+
 60+void progressbar_setpos(struct progressbar_state* state, int value, bool redraw)
 61+{
 62+ if (value > state->max) value = state->max;
 63+ if (value < state->min) value = state->min;
 64+ int newx = (value - state->min) * (state->endx - state->startx - 1)
 65+ / (state->max - state->min) + state->startx;
 66+ if (redraw || newx < state->currentx) progressbar_drawborderbg(state);
 67+ if (newx > state->currentx)
 68+ displaylcd(state->currentx + 1, newx, state->starty + 1, state->endy - 1,
 69+ (void*)-1, state->fgcolor);
 70+ state->currentx = newx;
 71+}
Index: embios/trunk/progressbar.h
@@ -0,0 +1,52 @@
 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 __PROGRESSBAR_H__
 26+#define __PROGRESSBAR_H__
 27+
 28+
 29+#include "global.h"
 30+#include "lcd.h"
 31+
 32+
 33+struct progressbar_state
 34+{
 35+ int startx;
 36+ int endx;
 37+ int starty;
 38+ int endy;
 39+ int bordercolor;
 40+ int bgcolor;
 41+ int fgcolor;
 42+ int currentx;
 43+ int min;
 44+ int max;
 45+};
 46+
 47+
 48+void progressbar_init(struct progressbar_state* state, int startx, int endx, int starty, int endy,
 49+ int bordercolor, int bgcolor, int fgcolor, int min, int max);
 50+void progressbar_setpos(struct progressbar_state* state, int value, bool redraw);
 51+
 52+
 53+#endif
Index: embios/trunk/export/syscallwrappers.h
@@ -71,6 +71,12 @@
7272 #define lcdconsole_putc(args...) __embios_syscall->lcdconsole_putc(args)
7373 #define lcdconsole_puts(args...) __embios_syscall->lcdconsole_puts(args)
7474 #define lcdconsole_write(args...) __embios_syscall->lcdconsole_write(args)
 75+#define lcdconsole_get_current_x(args...) __embios_syscall->lcdconsole_get_current_x(args)
 76+#define lcdconsole_get_current_y(args...) __embios_syscall->lcdconsole_get_current_y(args)
 77+#define lcdconsole_get_lineend_x(args...) __embios_syscall->lcdconsole_get_lineend_x(args)
 78+#define lcdconsole_get_lineend_y(args...) __embios_syscall->lcdconsole_get_lineend_y(args)
 79+#define progressbar_init(args...) __embios_syscall->progressbar_init(args)
 80+#define progressbar_setpos(args...) __embios_syscall->progressbar_setpos(args)
7581 #define shutdown(args...) __embios_syscall->shutdown(args)
7682 #define storage_read_sectors_md(args...) __embios_syscall->storage_read_sectors_md(args)
7783 #define storage_write_sectors_md(args...) __embios_syscall->storage_write_sectors_md(args)
@@ -116,6 +122,7 @@
117123 #define lcd_get_width(args...) __embios_syscall->lcd_get_width(args)
118124 #define lcd_get_height(args...) __embios_syscall->lcd_get_height(args)
119125 #define lcd_get_bytes_per_pixel(args...) __embios_syscall->lcd_get_bytes_per_pixel(args)
 126+#define lcd_translate_color(args...) __embios_syscall->lcd_translate_color(args)
120127 #define clean_dcache(args...) __embios_syscall->clean_dcache(args)
121128 #define invalidate_dcache(args...) __embios_syscall->invalidate_dcache(args)
122129 #define invalidate_icache(args...) __embios_syscall->invalidate_icache(args)
Index: embios/trunk/export/syscallapi.h
@@ -47,6 +47,7 @@
4848 #include "../execimage.h"
4949 #include "../backlight.h"
5050 #include "../syscall.h"
 51+#include "../progressbar.h"
5152 #include "../libc/include/string.h"
5253 #include "../libc/include/stdlib.h"
5354 #include "../libc/include/stdio.h"
@@ -107,6 +108,12 @@
108109 typeof(lcdconsole_putc) *lcdconsole_putc;
109110 typeof(lcdconsole_puts) *lcdconsole_puts;
110111 typeof(lcdconsole_write) *lcdconsole_write;
 112+ typeof(lcdconsole_get_current_x) *lcdconsole_get_current_x;
 113+ typeof(lcdconsole_get_current_y) *lcdconsole_get_current_y;
 114+ typeof(lcdconsole_get_lineend_x) *lcdconsole_get_lineend_x;
 115+ typeof(lcdconsole_get_lineend_y) *lcdconsole_get_lineend_y;
 116+ typeof(progressbar_init) *progressbar_init;
 117+ typeof(progressbar_setpos) *progressbar_setpos;
111118 typeof(shutdown) *shutdown;
112119 typeof(storage_read_sectors_md) *storage_read_sectors_md;
113120 typeof(storage_write_sectors_md) *storage_write_sectors_md;
@@ -152,6 +159,7 @@
153160 typeof(lcd_get_width) *lcd_get_width;
154161 typeof(lcd_get_height) *lcd_get_height;
155162 typeof(lcd_get_bytes_per_pixel) *lcd_get_bytes_per_pixel;
 163+ typeof(lcd_translate_color) *lcd_translate_color;
156164 typeof(clean_dcache) *clean_dcache;
157165 typeof(invalidate_dcache) *invalidate_dcache;
158166 typeof(invalidate_icache) *invalidate_icache;
Index: embios/trunk/SOURCES
@@ -40,6 +40,7 @@
4141 #ifdef HAVE_LCD
4242 drawing.S
4343 lcdconsole.c
 44+progressbar.c
4445 #endif
4546 format.c
4647 panic.c
Index: embios/trunk/syscallapi.c
@@ -23,30 +23,6 @@
2424
2525 #include "global.h"
2626 #include "syscallapi.h"
27 -#include "panic.h"
28 -#include "console.h"
29 -#include "dir.h"
30 -#include "file.h"
31 -#include "format.h"
32 -#include "lcdconsole.h"
33 -#include "storage.h"
34 -#include "shutdown.h"
35 -#include "thread.h"
36 -#include "ucl.h"
37 -#include "bootflash.h"
38 -#include "timer.h"
39 -#include "i2c.h"
40 -#include "interrupt.h"
41 -#include "lcd.h"
42 -#include "mmu.h"
43 -#include "nand.h"
44 -#include "power.h"
45 -#include "execimage.h"
46 -#include "backlight.h"
47 -#include "syscall.h"
48 -#include "libc/include/string.h"
49 -#include "libc/include/stdlib.h"
50 -#include "libc/include/stdio.h"
5127
5228
5329 struct embios_syscall_table syscall_table ICONST_ATTR =
@@ -153,6 +129,12 @@
154130 .lcdconsole_putc = lcdconsole_putc,
155131 .lcdconsole_puts = lcdconsole_puts,
156132 .lcdconsole_write = lcdconsole_write,
 133+ .lcdconsole_get_current_x = lcdconsole_get_current_x,
 134+ .lcdconsole_get_current_y = lcdconsole_get_current_y,
 135+ .lcdconsole_get_lineend_x = lcdconsole_get_lineend_x,
 136+ .lcdconsole_get_lineend_y = lcdconsole_get_lineend_y,
 137+ .progressbar_init = progressbar_init,
 138+ .progressbar_setpos = progressbar_setpos,
157139 .displaylcd = displaylcd,
158140 .displaylcd_sync = displaylcd_sync,
159141 .displaylcd_busy = displaylcd_busy,
@@ -160,6 +142,7 @@
161143 .lcd_get_width = lcd_get_width,
162144 .lcd_get_height = lcd_get_height,
163145 .lcd_get_bytes_per_pixel = lcd_get_bytes_per_pixel,
 146+ .lcd_translate_color = lcd_translate_color,
164147 #endif
165148 #ifdef HAVE_BACKLIGHT
166149 .backlight_on = backlight_on,
Index: embios/trunk/lcdconsole.c
@@ -133,3 +133,23 @@
134134 lcdconsole_needs_update = false;
135135 }
136136 }
 137+
 138+int lcdconsole_get_current_x()
 139+{
 140+ return (current_col + 1) * FONT_WIDTH + OFFSETX;
 141+}
 142+
 143+int lcdconsole_get_current_y()
 144+{
 145+ return current_row * FONT_HEIGHT + OFFSETY;
 146+}
 147+
 148+int lcdconsole_get_lineend_x()
 149+{
 150+ return LCDCONSOLE_COLS * FONT_WIDTH + OFFSETX - 1;
 151+}
 152+
 153+int lcdconsole_get_lineend_y()
 154+{
 155+ return (current_row + 1) * FONT_HEIGHT + OFFSETY - 1;
 156+}
Index: embios/trunk/lcdconsole.h
@@ -45,6 +45,10 @@
4646 void lcdconsole_write_noblit(const char* string, size_t length, int fgcolor, int bgcolor) ICODE_ATTR;
4747 void lcdconsole_update() ICODE_ATTR;
4848 void lcdconsole_callback() ICODE_ATTR;
 49+int lcdconsole_get_current_x() ICODE_ATTR;
 50+int lcdconsole_get_current_y() ICODE_ATTR;
 51+int lcdconsole_get_lineend_x() ICODE_ATTR;
 52+int lcdconsole_get_lineend_y() ICODE_ATTR;
4953
5054
5155 #endif