*
* -->
*
- * \brief Atmel SAM3X-EK testcase
+ * \brief Atmel SAM3X-EK wav player example.
*
* \author Stefano Fedrigo <aleph@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
*/
#include "bitmaps.h"
#include <cfg/debug.h>
-#include <cpu/irq.h>
#include <cpu/irq.h>
#include <cpu/byteorder.h>
#include <kern/signal.h>
#include <kern/proc.h>
+#include <kern/msg.h>
#include <fs/fat.h>
+#include <algo/wav.h>
+
#include <struct/list.h>
#include <verstag.h>
#include <buildrev.h>
+#include <stdio.h>
#include <string.h>
// Keyboard
#define KEY_MASK (K_LEFT | K_RIGHT)
-// Kernel
-#define PROC_STACK_SIZE KERN_MINSTACKSIZE * 2
-
-static PROC_DEFINE_STACK(hp_stack, PROC_STACK_SIZE);
-static PROC_DEFINE_STACK(lp_stack, PROC_STACK_SIZE);
-
/*
* Codec has 7-bit address, the eighth is the R/W bit, so we
* write the codec address with one bit shifted left
*/
#define CODEC_ADDR 0x36
+// Kernel
+static PROC_DEFINE_STACK(play_proc_stack, 1024);
+static PROC_DEFINE_STACK(rec_proc_stack, 1024);
+MsgPort proc_play_inPort;
+MsgPort proc_rec_inPort;
+#define MAX_ITEM_NODES 30
+#define MAX_ITEMS_ROW 15
+#define NEXT_ITEM_COL 10
-typedef struct WavHdr
+typedef struct FileItemNode
{
- char chunk_id[4];
- uint32_t chunk_size;
- char format[4];
-
- char subchunk1_id[4];
- uint32_t subchunk1_size;
- uint16_t audio_format;
- uint16_t num_channels;
- uint32_t sample_rate;
- uint32_t byte_rate;
- uint16_t block_align;
- uint16_t bits_per_sample;
-
- uint8_t subchunk2[8];
-} WavHdr;
-
+ Node n;
+ char file_name[13];
+} FileItemNode;
-static uint8_t raster[RAST_SIZE(LCD_WIDTH, LCD_HEIGHT)];
-static Bitmap lcd_bitmap;
-extern Font font_gohu;
-static int lcd_brightness = LCD_BACKLIGHT_MAX;
-static Process *hp_proc, *lp_proc;
-static hptime_t start, end;
+typedef struct AudioMsg
+{
+ Msg msg;
+ char file_name[13];
+} AudioMsg;
+FileItemNode item_nodes[MAX_ITEM_NODES];
-uint8_t tmp[4096];
+uint8_t tmp[10240];
// SD fat filesystem context
FATFS fs;
-FatFile log_file;
-FatFile acq_file;
+FatFile play_file;
+FatFile rec_file;
+static Sd sd;
static I2c i2c;
static I2s i2s;
static Wm8731 wm8731_ctx;
+static uint8_t raster[RAST_SIZE(LCD_WIDTH, LCD_HEIGHT)];
+static Bitmap lcd_bitmap;
+extern Font font_gohu;
+static int lcd_brightness = LCD_BACKLIGHT_MAX;
+static uint16_t headphone_volume = 90;
+static size_t played_size = 0;
+static size_t recorded_size = 0;
+static bool is_playing = false;
+static bool is_recording = false;
+static int recorderd_file_idx;
-static void screen_saver(Bitmap *bm)
+static void codec_play(struct I2s *i2s, void *_buf, size_t len)
{
- int x1, y1, x2, y2;
- int i;
-
- for (i = 0; ; i++)
+ played_size += kfile_read(&play_file.fd, _buf, len);
+ if (played_size >= play_file.fat_file.fsize - sizeof(WavHdr))
{
- x1 = i % LCD_WIDTH;
- y1 = i % LCD_HEIGHT;
-
- x2 = LCD_WIDTH - i % LCD_WIDTH;
- y2 = LCD_HEIGHT - i % LCD_HEIGHT;
-
- gfx_bitmapClear(bm);
- gfx_rectDraw(bm, x1, y1, x2, y2);
- lcd_hx8347_blitBitmap(bm);
- if (kbd_peek() & KEY_MASK)
- break;
+ kprintf("stop %d\n", played_size);
+ i2s_dmaTxStop(i2s);
+ is_playing = false;
+ played_size = 0;
}
}
-
-INLINE hptime_t get_hp_ticks(void)
+static void codec_rec(struct I2s *i2s, void *buf, size_t len)
{
- return (timer_clock_unlocked() * TIMER_HW_CNT) + timer_hw_hpread();
-}
+ (void)i2s;
+ ASSERT(buf);
+ ASSERT(len != 0);
+ ASSERT(&rec_file.fd);
-static void NORETURN hp_process(void)
-{
- while (1)
- {
- sig_wait(SIG_USER0);
- end = get_hp_ticks();
- timer_delay(100);
- sig_send(lp_proc, SIG_USER0);
- }
+ recorded_size += kfile_write(&rec_file.fd, buf, len);
}
-static void NORETURN lp_process(void)
+static void NORETURN play_proc(void)
{
while (1)
{
- start = get_hp_ticks();
- sig_send(hp_proc, SIG_USER0);
- sig_wait(SIG_USER0);
- }
-}
-
-/*
- * Lcd
- */
-static void setBrightness(Bitmap *bm)
-{
- while (1)
- {
- gfx_bitmapClear(bm);
- text_xprintf(bm, 1, 0, TEXT_FILL | TEXT_CENTER, "Brightness: %d", lcd_brightness);
- text_xprintf(bm, 3, 0, TEXT_FILL | TEXT_CENTER, "RIGHT key: change");
- text_xprintf(bm, 4, 0, TEXT_FILL | TEXT_CENTER, "LEFT key: back ");
- lcd_hx8347_blitBitmap(bm);
-
- keymask_t mask = kbd_get();
-
- if (mask & K_LEFT)
- break;
- else if (mask & K_RIGHT)
+ event_wait(&proc_play_inPort.event);
+ AudioMsg *play;
+ play = (AudioMsg *)msg_get(&proc_play_inPort);
+ if (play && SD_CARD_PRESENT())
{
- if (++lcd_brightness > LCD_BACKLIGHT_MAX)
- lcd_brightness = 0;
- lcd_setBacklight(lcd_brightness);
- }
- }
-}
+ timer_delay(10);
+ bool sd_ok = sd_init(&sd, NULL, 0);
+ FRESULT result;
-static void NORETURN soft_reset(Bitmap * bm)
-{
- int i;
+ if (sd_ok)
+ {
+ kprintf("Mount FAT filesystem.\n");
- gfx_bitmapClear(bm);
- for (i = 5; i; --i)
- {
- text_xprintf(bm, 2, 0, TEXT_FILL | TEXT_CENTER, "%d", i);
- lcd_hx8347_blitBitmap(bm);
- timer_delay(1000);
- }
- text_xprintf(bm, 2, 0, TEXT_FILL | TEXT_CENTER, "REBOOT");
- lcd_hx8347_blitBitmap(bm);
- timer_delay(1000);
+ result = f_mount(0, &fs);
+ if (result != FR_OK)
+ {
+ kprintf("Mounting FAT volumes error[%d]\n", result);
+ sd_ok = false;
+ }
- /* Perform a software reset request */
- HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;
- UNREACHABLE();
-}
+ if (sd_ok)
+ {
+ result = fatfile_open(&play_file, play->file_name, FA_OPEN_EXISTING | FA_READ);
+ if (result == FR_OK)
+ {
+ kprintf("Open file: %s size %ld\n", play->file_name, play_file.fat_file.fsize);
+ WavHdr wav;
+ kfile_read(&play_file.fd, &wav, sizeof(WavHdr));
+ if (wav_checkHdr(&wav, 1, CONFIG_CHANNEL_NUM, CONFIG_SAMPLE_FREQ, CONFIG_WORD_BIT_SIZE) != -1)
+ {
+ kputs("Wav file play..\n");
-static void read_adc(Bitmap *bm)
-{
- gfx_bitmapClear(bm);
- text_xprintf(bm, 0, 0, TEXT_FILL | TEXT_CENTER, "ADC Value");
- while (1)
- {
- uint16_t value = ADC_RANGECONV(adc_read(1), 0, 3300);
- uint16_t temp = hw_convertToDegree (adc_read(ADC_TEMPERATURE_CH));
+ wm8731_setVolume(&wm8731_ctx, WM8731_HEADPHONE, headphone_volume);
+ is_playing = true;
+ i2s_dmaStartTxStreaming(&i2s, tmp, sizeof(tmp), sizeof(tmp) / 2, codec_play);
- text_xprintf(&lcd_bitmap, 2, 0, TEXT_FILL | TEXT_CENTER,
- "Voltage on VR1: %d.%dV", value / 1000, value % 1000);
- text_xprintf(&lcd_bitmap, 3, 0, TEXT_FILL | TEXT_CENTER,
- "CPU temperature: %d.%dC", temp / 10, temp % 10);
- lcd_hx8347_blitBitmap(bm);
- timer_delay(400);
- if (kbd_peek() & KEY_MASK)
- break;
+ wm8731_setVolume(&wm8731_ctx, WM8731_HEADPHONE, 0);
+ }
+
+ // Flush data and close the files.
+ kfile_flush(&play_file.fd);
+ kfile_close(&play_file.fd);
+ }
+ else
+ {
+ kprintf("Unable to open file: '%s' error[%d]\n", play->file_name, result);
+ }
+ }
+ f_mount(0, NULL);
+ }
+ }
}
}
-#define FILE_NAME "outfile.wav"
-#define ACQ_FILE_NAME FILE_NAME
-
-
-uint8_t tmp[4096];
-
-// SD fat filesystem context
-FATFS fs;
-FatFile log_file;
-FatFile acq_file;
-
-static int wav_check(KFile *fd)
+static void NORETURN rec_proc(void)
{
-
- WavHdr header;
-
- if (kfile_read(fd, &header, sizeof(header)) != sizeof(header))
- {
- kputs("Error reading wave file header\n");
- return EOF;
- }
-
- if (strncmp(header.chunk_id, "RIFF", 4))
- {
- kputs("RIFF tag not found\n");
- goto error;
- }
-
- if (strncmp(header.format, "WAVE", 4))
+ while (1)
{
- kputs("WAVE tag not found\n");
- goto error;
- }
+ event_wait(&proc_rec_inPort.event);
+ AudioMsg *rec;
+ rec = (AudioMsg *)msg_get(&proc_rec_inPort);
+ if (rec && SD_CARD_PRESENT())
+ {
+ timer_delay(10);
- if (le16_to_cpu(header.audio_format) != 1)
- {
- kprintf("Audio format not valid, found [%d]\n", le16_to_cpu(header.audio_format));
- goto error;
- }
-
- if (le16_to_cpu(header.num_channels) != 2)
- {
- kprintf("Channels number not valid, found [%d]\n", le16_to_cpu(header.num_channels));
- goto error;
- }
+ bool sd_ok = sd_init(&sd, NULL, 0);
+ FRESULT result;
+ if (sd_ok)
+ {
+ kprintf("Mount FAT filesystem.\n");
- if (le32_to_cpu(header.sample_rate) != 44100)
- {
- kprintf("Sample rate not valid, found [%ld]\n", le32_to_cpu(header.sample_rate));
- goto error;
- }
+ result = f_mount(0, &fs);
+ if (result != FR_OK)
+ {
+ kprintf("Mounting FAT volumes error[%d]\n", result);
+ sd_ok = false;
+ }
- if (le16_to_cpu(header.bits_per_sample) != 16)
- {
- kprintf("Bits per sample not valid, found [%d]\n", le16_to_cpu(header.bits_per_sample));
- goto error;
+ if (sd_ok)
+ {
+ result = fatfile_open(&rec_file, rec->file_name, FA_CREATE_ALWAYS | FA_WRITE);
+ if (result == FR_OK)
+ {
+ kprintf("Open file: %s size %ld\n", rec->file_name, rec_file.fat_file.fsize);
+ kputs("Rec Wav file..\n");
+ is_recording = true;
+ // Leave place for wav header
+ kfile_seek(&rec_file.fd, sizeof(WavHdr), KSM_SEEK_SET);
+
+ i2s_dmaStartRxStreaming(&i2s, tmp, sizeof(tmp), sizeof(tmp) / 2, codec_rec);
+
+ // write header
+ WavHdr wav;
+ wav_writeHdr(&wav, recorded_size, 1, CONFIG_CHANNEL_NUM, CONFIG_SAMPLE_FREQ, CONFIG_WORD_BIT_SIZE);
+ kfile_seek(&rec_file.fd, 0, KSM_SEEK_SET);
+ kfile_write(&rec_file.fd, &wav, sizeof(WavHdr));
+
+ // Flush data and close the files.
+ kfile_flush(&rec_file.fd);
+ kfile_close(&rec_file.fd);
+ }
+ else
+ {
+ kprintf("Unable to open file: '%s' error[%d]\n", rec->file_name, result);
+ }
+ }
+ f_mount(0, NULL);
+ }
+ }
}
- return 0;
-
-error:
- return 1;
}
-static int wav_writeHdr(KFile *fd, uint16_t rate, uint16_t channels, uint16_t bits)
+INLINE void start_play(char *file_name)
{
- WavHdr header;
+ played_size = 0;
- memcpy(&header.chunk_id, "RIFF", 4);
- memcpy(&header.format, "WAVE", 4);
- header.audio_format = cpu_to_le16((uint16_t)1);
- header.num_channels = cpu_to_le16(channels);
- header.sample_rate = cpu_to_le16(rate);
- header.bits_per_sample = cpu_to_le16(bits);
-
- kfile_seek(fd, 0, KSM_SEEK_SET);
- kfile_write(fd, &header, sizeof(header));
-
- return 0;
+ AudioMsg play_msg;
+ memcpy(play_msg.file_name, file_name, sizeof(play_msg.file_name));
+ msg_put(&proc_play_inPort, &play_msg.msg);
}
-size_t count = 0;
-static void codec_play(struct I2s *i2s, void *_buf, size_t len)
+INLINE void stop_play(void)
{
- count += kfile_read(&log_file.fd, _buf, len);
- if (count >= log_file.fat_file.fsize - sizeof(WavHdr))
- {
- kprintf("stop %d\n", count);
- i2s_dmaTxStop(i2s);
- count = 0;
- }
+ i2s_dmaTxStop(&i2s);
+ is_playing = false;
}
-static void codec_rec(struct I2s *i2s, void *_buf, size_t len)
-{
- count += kfile_write(&acq_file.fd, _buf, len);
- if (count >= 1024 * 1024)
- {
- kprintf("stop %d\n", count);
- i2s_dmaRxStop(i2s);
- count = 0;
- }
-}
-
-
-#define MAX_ITEM_NODES 30
-#define MAX_ITEMS_ROW 15
-#define NEXT_ITEM_COL 10
-
-typedef struct FileItemNode
+INLINE void start_rec(char *file_name)
{
- Node n;
- char file_name[13];
-} FileItemNode;
+ recorded_size = 0;
-FileItemNode item_nodes[MAX_ITEM_NODES];
-static Sd sd;
+ AudioMsg rec_msg;
+ memcpy(rec_msg.file_name, file_name, sizeof(rec_msg.file_name));
+ msg_put(&proc_rec_inPort, &rec_msg.msg);
+}
-static void wav_play(Bitmap *bm, char *file_name)
+INLINE void stop_rec(void)
{
- gfx_bitmapClear(bm);
-
- kprintf("Mount FAT filesystem.\n");
- FRESULT result = f_mount(0, &fs);
- bool sd_ok = true;
- if (result != FR_OK)
- {
- kprintf("Mounting FAT volumes error[%d]\n", result);
- sd_ok = false;
- }
-
- if (sd_ok)
- {
- result = fatfile_open(&log_file, file_name, FA_OPEN_EXISTING | FA_READ);
- if (result == FR_OK)
- {
- text_xprintf(bm, 1, 0, TEXT_CENTER, "Play wav file: %s", file_name);
- text_xprintf(bm, 2, 0, TEXT_CENTER, "File: %ld", log_file.fat_file.fsize);
- text_xprintf(bm, 3, 0, TEXT_CENTER, "Volume level %ld", ADC_RANGECONV(adc_read(1), 0, 100));
- kprintf("Open file: %s\n", file_name);
- wm8731_setVolume(&wm8731_ctx, WM8731_HEADPHONE, ADC_RANGECONV(adc_read(1), 0, 100));
-
- lcd_hx8347_blitBitmap(bm);
- if (wav_check(&log_file.fd) >= 0)
- {
- kputs("Wav file play..\n");
- i2s_dmaStartTxStreaming(&i2s, tmp, sizeof(tmp), sizeof(tmp) / 4, codec_play);
- }
-
- wm8731_setVolume(&wm8731_ctx, WM8731_HEADPHONE, 0);
-
- // Flush data and close the files.
- kfile_flush(&log_file.fd);
- kfile_close(&log_file.fd);
- }
- else
- {
- kprintf("Unable to open file: '%s' error[%d]\n", FILE_NAME, result);
- }
- }
- f_mount(0, NULL);
-
- lcd_hx8347_blitBitmap(bm);
+ i2s_dmaRxStop(&i2s);
+ is_recording = false;
}
-
-INLINE FileItemNode *refresh_cursor(Bitmap *bm, List *file_list, int select_idx)
+INLINE FileItemNode *select_item(Bitmap *bm, List *file_list, int select_idx)
{
FileItemNode *item;
FileItemNode *select_node;
if (select_idx <= MAX_ITEMS_ROW)
{
if (row == select_idx && col == 0)
+ {
text_style(bm, STYLEF_INVERT, STYLEF_INVERT);
select_node = item;
+ }
}
else
{
if (row == (select_idx - MAX_ITEMS_ROW) && col == NEXT_ITEM_COL)
+ {
text_style(bm, STYLEF_INVERT, STYLEF_INVERT);
select_node = item;
+ }
}
text_xprintf(bm, row, col, TEXT_NORMAL, "%s", item->file_name);
return select_node;
}
-static void sd_explorer(Bitmap *bm)
+static void play_menu(Bitmap *bm)
{
List file_list;
LIST_INIT(&file_list);
if (sd_ok)
{
kprintf("Mount FAT filesystem.\n");
-
result = f_mount(0, &fs);
if (result != FR_OK)
{
break; /* Break on error or end of dir */
if (fno.fname[0] == '.')
continue; /* Ignore dot entry */
-
if (fno.fattrib & AM_DIR)
continue;
else
memcpy (&item_nodes[i].file_name, fno.fname, sizeof(item_nodes[i].file_name));
ADDTAIL(&file_list, &item_nodes[i].n);
file_list_size++;
+ kprintf("%s\n", item_nodes[i].file_name);
}
else
{
- kputs("No enought spase to show file list..\n");
+ kputs("No enought space to store items in list\n");
break;
}
}
}
int idx = 0;
- FileItemNode *selected_node = refresh_cursor(bm, &file_list, idx);
+ FileItemNode *selected_node = NULL;
+ select_item(bm, &file_list, idx);
while (1)
{
keymask_t key = kbd_peek();
- if (key & K_LEFT)
+ if ((key & K_LEFT) && !is_playing)
{
idx++;
if (idx > file_list_size)
idx = 0;
- selected_node = refresh_cursor(bm, &file_list, idx);
- kprintf("lidx[%d]\n", idx);
+ selected_node = select_item(bm, &file_list, idx);
}
if (key & K_RIGHT)
{
- kprintf("ridx[%d]\n", idx);
- wav_play(bm, selected_node->file_name);
if (idx == 0)
break;
+
+ if (!is_playing)
+ start_play(selected_node->file_name);
+ else
+ stop_play();
}
+
+ cpu_relax();
}
}
-static void test_draw(Bitmap *bm)
+
+static void rec_menu(Bitmap *bm)
{
gfx_bitmapClear(bm);
- text_xprintf(bm, 0, 0, TEXT_NORMAL, "%s\n", "12345678.123");
- text_xprintf(bm, 0, 10, TEXT_NORMAL, "%s\n", "12345678.123");
- text_xprintf(bm, 1, 0, TEXT_NORMAL, "%s\n", "12345678.123");
- text_xprintf(bm, 2, 0, TEXT_NORMAL, "%s\n", "12345678.123");
- text_xprintf(bm, 3, 0, TEXT_NORMAL, "%s\n", "12345678.123");
+ text_style(bm, STYLEF_BOLD | STYLEF_UNDERLINE, STYLEF_BOLD | STYLEF_UNDERLINE);
+ text_xprintf(bm, 0, 0, TEXT_CENTER | TEXT_FILL, "Microphone recorder.");
+ text_style(bm, 0, STYLEF_MASK);
+ text_xprintf(bm, 2, 0, TEXT_NORMAL, "Press RIGHT button to start recording");
+ text_xprintf(bm, 3, 0, TEXT_NORMAL, "and to stop it re-press RIGHT button.");
lcd_hx8347_blitBitmap(bm);
- timer_delay(400);
+ ticks_t start= 0;
+ while (1)
+ {
+ keymask_t key = kbd_peek();
+ if ((key & K_LEFT) && (!is_recording))
+ {
+ break;
+ }
+ if (key & K_RIGHT)
+ {
+ char file_name[13];
+ memset(file_name, 0, sizeof(file_name));
+ sprintf(file_name, "REC%d.WAV", recorderd_file_idx);
+ kprintf("rec %s\n", file_name);
+
+ if (!is_recording)
+ {
+ start_rec(file_name);
+ text_xprintf(bm, 5, 0, TEXT_CENTER | TEXT_FILL, "Start recording on file: %s", file_name);
+ text_xprintf(bm, 6, 0, TEXT_CENTER | TEXT_FILL, " ");
+ lcd_hx8347_blitBitmap(bm);
+ start = timer_clock();
+ }
+ else
+ {
+ stop_rec();
+ recorderd_file_idx++;
+ text_xprintf(bm, 5, 0, TEXT_CENTER | TEXT_FILL, "Stop recording: %s", file_name);
+ mtime_t elaps = ticks_to_ms(timer_clock() - start);
+ text_xprintf(bm, 6, 0, TEXT_CENTER | TEXT_FILL, "Recorded: %ld.%ldsec", elaps / 1000, elaps % 1000);
+ lcd_hx8347_blitBitmap(bm);
+ }
+ }
+
+ cpu_relax();
+ }
+}
+
+
+
+/*
+ * Lcd
+ */
+static void setBrightness(Bitmap *bm)
+{
+ while (1)
+ {
+ gfx_bitmapClear(bm);
+ text_xprintf(bm, 1, 0, TEXT_FILL | TEXT_CENTER, "Brightness: %d", lcd_brightness);
+ text_xprintf(bm, 3, 0, TEXT_FILL | TEXT_CENTER, "RIGHT key: change");
+ text_xprintf(bm, 4, 0, TEXT_FILL | TEXT_CENTER, "LEFT key: back ");
+ lcd_hx8347_blitBitmap(bm);
+
+ keymask_t mask = kbd_get();
+
+ if (mask & K_LEFT)
+ break;
+ else if (mask & K_RIGHT)
+ {
+ if (++lcd_brightness > LCD_BACKLIGHT_MAX)
+ lcd_brightness = 0;
+ lcd_setBacklight(lcd_brightness);
+ }
+ }
+}
+
+static void setVolume(Bitmap *bm)
+{
+ gfx_bitmapClear(bm);
+ text_style(bm, STYLEF_BOLD | STYLEF_UNDERLINE, STYLEF_BOLD | STYLEF_UNDERLINE);
+ text_xprintf(bm, 0, 0, TEXT_CENTER, "Headphone Volume");
+ text_style(bm, 0, STYLEF_MASK);
+ text_xprintf(bm, 2, 0, TEXT_NORMAL, "Turn VR1 potentiometer to adjust it.");
+
while (1)
+ {
+ headphone_volume = ADC_RANGECONV(adc_read(1), 0, 100);
+ text_xprintf(bm, 5, 0, TEXT_FILL | TEXT_CENTER, "Volume %d%%", headphone_volume);
+ lcd_hx8347_blitBitmap(bm);
+
+ timer_delay(400);
if (kbd_peek() & KEY_MASK)
break;
+ }
}
-static struct MenuItem sub_items[] =
+static void NORETURN soft_reset(Bitmap * bm)
{
- { (const_iptr_t)"un", 0, (MenuHook)0, NULL },
- { (const_iptr_t)"du", 0, (MenuHook)0, NULL },
- { (const_iptr_t)"tr", 0, (MenuHook)0, NULL },
- { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
-};
-static struct Menu sub_menu = { sub_items, "BeRTOS", MF_SAVESEL, &lcd_bitmap, 0, lcd_hx8347_blitBitmap };
+ int i;
+
+ gfx_bitmapClear(bm);
+ for (i = 5; i; --i)
+ {
+ text_xprintf(bm, 2, 0, TEXT_FILL | TEXT_CENTER, "%d", i);
+ lcd_hx8347_blitBitmap(bm);
+ timer_delay(1000);
+ }
+ text_xprintf(bm, 2, 0, TEXT_FILL | TEXT_CENTER, "REBOOT");
+ lcd_hx8347_blitBitmap(bm);
+ timer_delay(1000);
+
+ /* Perform a software reset request */
+ HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;
+ UNREACHABLE();
+}
+
static struct MenuItem main_items[] =
{
- { (const_iptr_t)"Screen saver demo", 0, (MenuHook)screen_saver, &lcd_bitmap },
- { (const_iptr_t)"Display brightness", 0, (MenuHook)setBrightness, &lcd_bitmap },
- { (const_iptr_t)"SD dir", 0, (MenuHook)sd_explorer, (iptr_t)&lcd_bitmap },
- { (const_iptr_t)"Reboot", 0, (MenuHook)soft_reset, &lcd_bitmap },
+ { (const_iptr_t)"Play SD file", 0, (MenuHook)play_menu, (iptr_t)&lcd_bitmap },
+ { (const_iptr_t)"Record file on SD", 0, (MenuHook)rec_menu, (iptr_t)&lcd_bitmap },
+ { (const_iptr_t)"Set brightness", 0, (MenuHook)setBrightness, (iptr_t)&lcd_bitmap },
+ { (const_iptr_t)"Set volume", 0, (MenuHook)setVolume, (iptr_t)&lcd_bitmap },
+ { (const_iptr_t)"Reboot", 0, (MenuHook)soft_reset, (iptr_t)&lcd_bitmap },
{ (const_iptr_t)0, 0, NULL, (iptr_t)0 }
};
static struct Menu main_menu = { main_items, "BeRTOS", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0, lcd_hx8347_blitBitmap };
kprintf("CPU Frequecy:%ld\n", CPU_FREQ);
-
- /* Enable the adc to read internal temperature sensor */
- hw_enableTempRead();
-
-
lcd_hx8347_init();
lcd_setBacklight(lcd_brightness);
kbd_init();
- hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack);
- lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack);
-
- proc_setPri(hp_proc, 2);
- proc_setPri(lp_proc, 1);
+ proc_new(play_proc, NULL, sizeof(play_proc_stack), play_proc_stack);
+ proc_new(rec_proc, NULL, sizeof(rec_proc_stack), rec_proc_stack);
+ msg_initPort(&proc_play_inPort, event_createGeneric());
+ msg_initPort(&proc_rec_inPort, event_createGeneric());
lcd_hx8347_blitBitmap24(10, 52, BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, bmp_logo);
timer_delay(500);