A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 194 lines 4.5 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2007 by Dave Chapman 11 * 12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing 13 * 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License 16 * as published by the Free Software Foundation; either version 2 17 * of the License, or (at your option) any later version. 18 * 19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20 * KIND, either express or implied. 21 * 22 ****************************************************************************/ 23#include "config.h" 24 25#include <stdlib.h> 26#include <stdio.h> 27#include <string.h> 28#include "cpu.h" 29#include "system.h" 30#include "lcd.h" 31#include "../kernel-internal.h" 32#include "storage.h" 33#include "file_internal.h" 34#include "disk.h" 35#include "font.h" 36#include "button.h" 37#include "adc.h" 38#include "adc-target.h" 39#include "backlight.h" 40#include "backlight-target.h" 41#include "panic.h" 42#include "power.h" 43#include "file.h" 44#include "common.h" 45#include "rb-loader.h" 46#include "loader_strerror.h" 47#include "version.h" 48 49/* Show the Rockbox logo - in show_logo.c */ 50extern void show_logo(void); 51 52/* Address to load main Rockbox image to */ 53#define LOAD_ADDRESS 0x20000000 /* DRAM_START */ 54 55extern int line; 56 57#define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */ 58 59/* The following function is just test/development code */ 60void show_debug_screen(void) 61{ 62 int button; 63 int power_count = 0; 64 int count = 0; 65 bool do_power_off = false; 66 67 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---"); 68 while (!do_power_off) { 69 line = 1; 70 button = button_get(false); 71 72 /* Power-off if POWER button has been held for a time 73 This loop is currently running at about 100 iterations/second 74 */ 75 if (button & POWEROFF_BUTTON) { 76 power_count++; 77 if (power_count > 100) 78 do_power_off = true; 79 } else { 80 power_count = 0; 81 } 82#if 0 83 if (button & BUTTON_SELECT){ 84 backlight_hw_off(); 85 } 86 else{ 87 backlight_hw_on(); 88 } 89#endif 90 printf("Btn: 0x%08x",button); 91#if 0 92 printf("Tick: %d",current_tick); 93 printf("GPIOA: 0x%08x",GPIOA); 94 printf("GPIOB: 0x%08x",GPIOB); 95 printf("GPIOC: 0x%08x",GPIOC); 96 printf("GPIOD: 0x%08x",GPIOD); 97 printf("GPIOE: 0x%08x",GPIOE); 98#endif 99 100#if 0 101 int i; 102 for (i = 0; i<4; i++) 103 { 104 printf("ADC%d: 0x%04x",i,adc_read(i)); 105 } 106#endif 107 count++; 108 printf("Count: %d",count); 109 lcd_update(); 110 sleep(HZ/10); 111 112 } 113 114 lcd_clear_display(); 115 line = 0; 116 printf("POWER-OFF"); 117 118 /* Power-off */ 119 power_off(); 120 121 printf("(NOT) POWERED OFF"); 122 while (true); 123} 124 125void* main(void) 126{ 127#ifdef TCCBOOT 128 int rc; 129 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS; 130#endif 131 132 system_init(); 133 power_init(); 134 135 kernel_init(); 136 enable_irq(); 137 138 lcd_init(); 139 140 adc_init(); 141 button_init(); 142 backlight_init(); 143 144 font_init(); 145 lcd_setfont(FONT_SYSFIXED); 146 147 show_logo(); 148 149 backlight_hw_on(); 150 151/* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is 152 available for loading the firmware. Otherwise display the debug screen. */ 153#ifdef TCCBOOT 154 printf("Rockbox boot loader"); 155 printf("Version %s", rbversion); 156 157 printf("ATA"); 158 rc = storage_init(); 159 if(rc) 160 { 161 reset_screen(); 162 error(EATA, rc, true); 163 } 164 165 filesystem_init(); 166 167 printf("mount"); 168 rc = disk_mount_all(); 169 if (rc<=0) 170 { 171 error(EDISK,rc, true); 172 } 173 174 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE); 175 176 if (rc <= EFILE_EMPTY) 177 { 178 error(EBOOTFILE,rc, true); 179 } 180 else 181 { 182 int(*kernel_entry)(void) = (void *) loadbuffer; 183 184 disable_irq(); 185 rc = kernel_entry(); 186 } 187 188 panicf("Boot failed!"); 189#else 190 show_debug_screen(); 191#endif 192 193 return 0; 194}