Kaynağa Gözat

v20220606.patch01

huangliang 2 yıl önce
ebeveyn
işleme
e84960ea5f

+ 3 - 0
STEPLDR/Src/Entry.c

@@ -169,6 +169,7 @@ readapp:
 	} else {
 		UpFileHeader *header = (UpFileHeader *)IMAGE_ENTRY;
 		UINT32 woff = IMAGE_OFFSET;
+		UINT32 app_size;
 
 		while (leftsize > 0) {
 			fret = f_read(&fp, (void *)IMAGE_ENTRY, IMAGE_READ_SIZE, &size);
@@ -186,6 +187,7 @@ readapp:
 					calc_checksum = 0xffffffff;
 					checksum = header->checksum;
 					header->checksum = 0;
+					app_size = header->files[0].size;
 				}
 				calc_checksum = xcrc32((unsigned char*)IMAGE_ENTRY, size, calc_checksum);
 				if (SpiNorBurn((void*)IMAGE_ENTRY, woff, size, 0)) {
@@ -204,6 +206,7 @@ readapp:
 			SendUartString("app checksum fail, update again.\n");
 		} else {
 			sysinfo->app_checksum = header->checksum = checksum;
+			sysinfo->app_size = app_size;
 			update_ok = 1;
 		}
 	}

BIN
Tools/630H烧录文件合成工具/filem.exe


+ 11 - 10
amt630h-freertos/ArkmicroFiles/libcpu-amt630h/include/i2s.h

@@ -19,14 +19,13 @@
 #define I2S_ADCR0		0x1C  /* ADC Contol Register */
 #define I2S_SADR		0x80  /* Serial Audio Data Register (TX and RX FIFO access Register). */
 
-#define SACR0_VREF_VOLSEL		(1 << 28)	/* Sel VREF Voltage 0:3.3v 1:2.2v */
-#define SACR0_ADC_VOLSET		(1 << 27)	/* Sel ADC PGA op commond voltage 0:��.5v 1:1.65v */
-#define SACR0_MIC_LINE_SEL		(1 << 26)	/* Select micin or linein */
-#define SACR0_SDRADC_POWEN		(1 << 25)	/* SARADC power Enable */
-#define SACR0_DATA_SEL			(1 << 24)	/* Select external i2s data or sdradc data */
-#define SACR0_SARADC_DIS		(1 << 23)	/* SARADC Disable */
-#define SACR0_DAC_PD	(1 << 22)	/* DAC Power down */
-#define SACR0_VREF_PD	(1 << 21)	/* VREF Power down */
+#define SACR0_CH_ALIGH		(1 << 27)	/* channel align in 32bit mode */
+#define SACR0_RLFIRST		(1 << 26)	/* RX FIFO left ch first */
+#define SACR0_TLFIRST		(1 << 25)	/* TX FIFO left ch first */
+#define SACR0_CH_LOCK		(1 << 24)	/* Load RLFIRST TLFIRST setting */
+#define SACR0_MOLO_MODE		(1 << 23)	/* single channel mode */
+#define SACR0_32BIT_MODE	(1 << 22)	/* S32_LE mode */
+#define SACR0_SYNC_INV		(1 << 21)	/* Left/Right ch switch */
 #define SACR0_RFTH_MASK	(0x1F << 16)
 #define SACR0_RFTH(x)	((x) << 16)	/* Rx FIFO Interrupt or DMA Trigger Threshold */
 #define SACR0_TFTH(x)	((x) << 8)	/* Tx FIFO Interrupt or DMA Trigger Threshold */
@@ -89,14 +88,16 @@ struct ark_i2s_data {
 	unsigned int nco_reg;
 	int clkid;
 	int master;
-	int extdata;
+	int channels;
+	int samplebits;
 	struct dma_chan *dma_ch;
 	int dma_args[3];
 };
 
 int ark_i2s_init(struct ark_i2s_data *i2s);
-void ark_i2s_set_volume(struct ark_i2s_data *i2s, int lvol, int rvol);
 int ark_i2s_set_rate(struct ark_i2s_data *i2s, unsigned int rate);
+int ark_i2s_set_channels(struct ark_i2s_data *i2s, int channels);
+int ark_i2s_set_samplebits(struct ark_i2s_data *i2s, int bits);
 int ark_i2s_startup(struct ark_i2s_data *i2s, int stream);
 void ark_i2s_stop(struct ark_i2s_data *i2s, int stream);
 

+ 1 - 1
amt630h-freertos/ArkmicroFiles/libcpu-amt630h/source/audio/audio.c

@@ -362,7 +362,7 @@ size_t audio_dev_write(struct audio_device *audio, const void *buffer, size_t si
 			uint32_t st = xTaskGetTickCount();
         	while(1) {
 				int i;
-				portENABLE_INTERRUPTS();
+				portENTER_CRITICAL();
 				for (i = 0; i < AUDIO_REPLAY_MP_BLOCK_COUNT; i++) {
 					if (!audio->replay->mpstatus[i]) {
 						mpbuf = audio->replay->mempool + AUDIO_REPLAY_MP_BLOCK_SIZE * i;

+ 5 - 4
amt630h-freertos/ArkmicroFiles/libcpu-amt630h/source/audio/drv_sound.c

@@ -13,7 +13,8 @@ struct ark_i2s_data amt630h_i2s_dac = {
 	.nco_reg = I2S_DAC_NCO_REG,
 	.clkid = CLK_I2S,
 	.master = 1,
-	.extdata = 0,
+	.channels = 2,
+	.samplebits = 16,
 };
 
 struct sound_device
@@ -56,7 +57,7 @@ static int ark_audio_stop(struct audio_device *audio, int stream)
 {
 	configASSERT(audio != NULL);
 	
-	ark_i2s_stop(snd_dev.i2s, stream);
+	//ark_i2s_stop(snd_dev.i2s, stream);
     dma_stop_channel(snd_dev.i2s->dma_ch);
 
     return 0;
@@ -156,7 +157,6 @@ static int ark_audio_configure(struct audio_device *audio, struct audio_caps *ca
         {
         case AUDIO_MIXER_MUTE:
         {
-			ark_i2s_set_volume(snd_dev.i2s, 0, 0);
             snd_dev.volume = 0;
             break;
         }
@@ -165,7 +165,6 @@ static int ark_audio_configure(struct audio_device *audio, struct audio_caps *ca
         {
             int volume = caps->udata.value;
 			
-          	ark_i2s_set_volume(snd_dev.i2s, volume, volume);
             snd_dev.volume = volume;
             break;
         }
@@ -184,6 +183,8 @@ static int ark_audio_configure(struct audio_device *audio, struct audio_caps *ca
             snd_dev.replay_config.samplerate = config.samplerate;
 
 			ark_i2s_set_rate(snd_dev.i2s, config.samplerate);
+			ark_i2s_set_channels(snd_dev.i2s, config.channels);
+			ark_i2s_set_samplebits(snd_dev.i2s, config.samplebits);
             break;
         }
 

+ 51 - 27
amt630h-freertos/ArkmicroFiles/libcpu-amt630h/source/i2s.c

@@ -5,24 +5,14 @@
 #include "audio/audio.h"
 #include "i2s.h"
 
-static void ark_i2s_poweron(struct ark_i2s_data *i2s)
-{
-	uint32_t val;
-
-	val = readl(i2s->base + I2S_SACR0);
-	val &= ~(SACR0_VREF_PD | SACR0_DAC_PD);
-	val |= SACR0_SDRADC_POWEN;
-	writel(val, i2s->base + I2S_SACR0);
-}
-
 int ark_i2s_startup(struct ark_i2s_data *i2s, int stream)
 {
 	unsigned int val;
 
 	/* reset */
-	writel(SACR0_RST, i2s->base + I2S_SACR0);
+	/* writel(SACR0_RST, i2s->base + I2S_SACR0);
 	udelay(1);
-	writel(0, i2s->base + I2S_SACR0);
+	writel(0, i2s->base + I2S_SACR0); */
 
 	if (stream == AUDIO_STREAM_REPLAY) {
 		writel(SACR1_DREC, i2s->base + I2S_SACR1);
@@ -31,9 +21,13 @@ int ark_i2s_startup(struct ark_i2s_data *i2s, int stream)
 		writel(0x7f, i2s->base + I2S_SAICR);
 		writel(0, i2s->base + I2S_SAICR);
 
-		val = SACR0_DATA_SEL | SACR0_TFTH(15) | SACR0_TDMAEN | SACR0_ENB;
+		val = SACR0_TLFIRST | SACR0_CH_LOCK | SACR0_TFTH(15) | SACR0_TDMAEN | SACR0_ENB;
 		if (i2s->master)
 			val |= SACR0_BCKD | SACR0_SYNCD;
+		if (i2s->channels == 1)
+			val |= SACR0_MOLO_MODE;
+		if (i2s->samplebits == 32)
+			val |= SACR0_32BIT_MODE;
 		writel(val, i2s->base + I2S_SACR0);	
 
 	} else if(stream == AUDIO_STREAM_RECORD) {
@@ -50,25 +44,15 @@ int ark_i2s_startup(struct ark_i2s_data *i2s, int stream)
 		writel(0x7f, i2s->base + I2S_SAICR);
 		writel(0, i2s->base + I2S_SAICR);
 
-		val = SACR0_SDRADC_POWEN | SACR0_DATA_SEL | SACR0_SARADC_DIS | 
-				SACR0_RFTH(16) | SACR0_RDMAEN | SACR0_ENB;
+		val = SACR0_RLFIRST | SACR0_CH_LOCK | SACR0_RFTH(16) | SACR0_RDMAEN | SACR0_ENB;
 		if (i2s->master)
 			val |= SACR0_BCKD | SACR0_SYNCD;
-		if (i2s->extdata) {
-			val &= ~SACR0_DATA_SEL;
-			val |= SACR0_MIC_LINE_SEL | SACR0_DAC_PD | SACR0_VREF_PD;
-		}
 		writel(val, i2s->base + I2S_SACR0);		
 	}
 
 	return 0;
 }
 
-void ark_i2s_set_volume(struct ark_i2s_data *i2s, int lvol, int rvol)
-{
-	writel(DACR0_LVOL(lvol) | DACR0_RVOL(rvol), i2s->base + I2S_DACR0);
-}
-
 int ark_i2s_set_rate(struct ark_i2s_data *i2s, unsigned int rate)
 {
 	u32 step = 256 * 2, modulo;
@@ -86,6 +70,48 @@ int ark_i2s_set_rate(struct ark_i2s_data *i2s, unsigned int rate)
 	return 0;
 }
 
+int ark_i2s_set_channels(struct ark_i2s_data *i2s, int channels)
+{
+	unsigned int val;
+
+	if (channels != 1 && channels != 2) {
+		printf("Unsupported i2s channels %d.\n", channels);
+		return -1;
+	}
+
+	val = readl(i2s->base + I2S_SACR0);
+	if (channels == 1)
+		val |= SACR0_MOLO_MODE;
+	else
+		val &= ~SACR0_MOLO_MODE;
+	writel(val, i2s->base + I2S_SACR0);
+
+	i2s->channels = channels;
+
+	return 0;
+}
+
+int ark_i2s_set_samplebits(struct ark_i2s_data *i2s, int bits)
+{
+	unsigned int val;
+
+	if (bits != 16 && bits != 32) {
+		printf("Unsupported i2s samplebits %d.\n", bits);
+		return -1;
+	}
+
+	val = readl(i2s->base + I2S_SACR0);
+	if (bits == 32)
+		val |= SACR0_32BIT_MODE;
+	else
+		val &= ~SACR0_32BIT_MODE;
+	writel(val, i2s->base + I2S_SACR0);
+
+	i2s->samplebits = bits;
+
+	return 0;
+}
+
 void ark_i2s_stop(struct ark_i2s_data *i2s, int stream)
 {
 	if (stream == AUDIO_STREAM_REPLAY)
@@ -118,9 +144,7 @@ int ark_i2s_init(struct ark_i2s_data *i2s)
 
 	sys_soft_reset(softreset_i2s);
 
-	request_irq(I2S_IRQn, 0, i2s_interrupt_handler, i2s);
-
-	ark_i2s_poweron(i2s);
+	//request_irq(I2S_IRQn, 0, i2s_interrupt_handler, i2s);
 
 	return 0;
 }

+ 36 - 5
amt630h-freertos/ArkmicroFiles/libcpu-amt630h/source/lcd.c

@@ -1,6 +1,7 @@
 #include <string.h>
 
 #include "FreeRTOS.h"
+#include "event_groups.h"
 #include "chip.h"
 #include "board.h"
 
@@ -123,10 +124,17 @@ struct ark_lcd_timing
 	uint32_t hsw;
 };
 
+#if configUSE_16_BIT_TICKS == 1
+#define MAX_VSYNC_WAIT_TASKS	8
+#else
+#define MAX_VSYNC_WAIT_TASKS	24
+#endif
 struct ark_lcd_data
 {
 	struct ark_lcd_timing timing;
-	QueueHandle_t vsync_waitq;
+	EventGroupHandle_t vsync_waitq;
+	void *waitq_tasks[MAX_VSYNC_WAIT_TASKS];
+	uint32_t waitbits;
 };
 
 
@@ -610,6 +618,7 @@ int ark_lcd_enable(uint8_t enable)
 int ark_lcd_wait_for_vsync(void)
 {
 	struct ark_lcd_data *lcd = g_lcd;
+	int i;
 
 	if(!lcd) {
 		printf("ERR: %s, Invalid lcd(NULL)\n", __func__);
@@ -617,8 +626,27 @@ int ark_lcd_wait_for_vsync(void)
 	}
 
 #if LCD_INTERFACE_TYPE != LCD_INTERFACE_CPU
-	xQueueReset(lcd->vsync_waitq);
-	xQueueReceive(lcd->vsync_waitq, NULL, portMAX_DELAY);
+	portENTER_CRITICAL();
+	for (i = 0; i < MAX_VSYNC_WAIT_TASKS; i++) {
+		if (lcd->waitq_tasks[i] == xTaskGetCurrentTaskHandle()) {
+			lcd->waitbits |= 1 << i;
+			break;
+		} else if (lcd->waitq_tasks[i] == NULL) {
+			lcd->waitq_tasks[i] = xTaskGetCurrentTaskHandle();
+			lcd->waitbits |= 1 << i;
+			break;
+		}
+	}
+	portEXIT_CRITICAL();
+	if (i == MAX_VSYNC_WAIT_TASKS) {
+		printf("ERR: %s, waitq_tasks full\n", __func__);
+		return -1;
+	}
+	xEventGroupClearBits(lcd->vsync_waitq, 1 << i);
+	xEventGroupWaitBits(lcd->vsync_waitq, 1 << i, pdFALSE, pdFALSE, pdMS_TO_TICKS(50));
+	portENTER_CRITICAL();
+	lcd->waitbits &= ~(1 << i);
+	portEXIT_CRITICAL();
 #endif
 	return 0;
 }
@@ -1007,7 +1035,8 @@ static void ark_lcd_interrupt(void *param)
 		for (i = 0; i < LCD_OSD_NUMS; i++)
 			g_osdConfig[i] = 0;
 
-		xQueueSendFromISR(lcd->vsync_waitq, NULL, 0);
+		if (lcd->waitbits)
+			xEventGroupSetBitsFromISR(lcd->vsync_waitq, lcd->waitbits, NULL);
 	}
 }
 
@@ -1039,6 +1068,8 @@ int lcd_init(void)
 	}
 	fb_addr = (uint32_t)fb_buf;
 
+	sys_soft_reset(softreset_lcd);
+
 	/* lcd timing init */
 	lcd->timing.vs_start = 0;
 	lcd->timing.hs_start = 0;
@@ -1067,7 +1098,7 @@ int lcd_init(void)
 
 	ark_lcd_timing_init(lcd);
 
-	lcd->vsync_waitq = xQueueCreate(1, 0);
+	lcd->vsync_waitq = xEventGroupCreate();
 
 	ark_lcd_hw_init();
 

+ 35 - 5
amt630h-freertos/app/main_lvgl.c

@@ -179,7 +179,7 @@ static void usb_read_demo(void)
 #ifdef AUDIO_REPLAY
 #include "audio.h"
 
-#define BUFSZ   1024
+#define BUFSZ   4096
 
 struct RIFF_HEADER_DEF
 {
@@ -218,15 +218,25 @@ struct wav_info
     struct DATA_BLOCK_DEF  data_block;
 };
 
+#define ROMFILE_ADUIO
 static void wavplay_thread(void *param)
 {
+#ifdef ROMFILE_ADUIO
     RomFile *file = NULL;
+#else
+	FF_FILE *file = NULL;
+#endif
     uint8_t *buffer = NULL;
     struct wav_info *info = NULL;
     struct audio_caps caps = {0};
 	struct audio_device *audio;
+	int data_size;
 
+#ifdef ROMFILE_ADUIO
     file = RomFileOpen("audio/sin1K.wav");
+#else
+	file = ff_fopen("/sd/audio/sin1K", "rb");
+#endif
     if (!file)
     {
         printf("open file failed!\n");
@@ -241,12 +251,25 @@ static void wavplay_thread(void *param)
     if (info == NULL)
         goto __exit;
 
+#ifdef ROMFILE_ADUIO
     if (RomFileRead(file, &(info->header), sizeof(struct RIFF_HEADER_DEF)) <= 0)
         goto __exit;
     if (RomFileRead(file, &(info->fmt_block),  sizeof(struct FMT_BLOCK_DEF)) <= 0)
         goto __exit;
+	if (info->fmt_block.fmt_size > sizeof(struct WAVE_FORMAT_DEF))
+		RomFileSeek(file, info->fmt_block.fmt_size - sizeof(struct WAVE_FORMAT_DEF), SEEK_CUR);
     if (RomFileRead(file, &(info->data_block), sizeof(struct DATA_BLOCK_DEF)) <= 0)
         goto __exit;
+#else
+    if (ff_fread(&(info->header), sizeof(struct RIFF_HEADER_DEF), 1, file) <= 0)
+        goto __exit;
+    if (ff_fread(&(info->fmt_block),  sizeof(struct FMT_BLOCK_DEF), 1, file) <= 0)
+        goto __exit;
+	if (info->fmt_block.fmt_size > sizeof(struct WAVE_FORMAT_DEF))
+		ff_fseek(file, info->fmt_block.fmt_size - sizeof(struct WAVE_FORMAT_DEF), FF_SEEK_CUR);
+    if (ff_fread(&(info->data_block), sizeof(struct DATA_BLOCK_DEF), 1, file) <= 0)
+        goto __exit;
+#endif
 
     printf("wav information:\n");
     printf("samplerate %d\n", info->fmt_block.wav_format.SamplesPerSec);
@@ -267,30 +290,37 @@ static void wavplay_thread(void *param)
     caps.udata.config.samplebits = 16;                                          /* 采样位数 */
     audio_dev_configure(audio, &caps);
 
-	audio = audio_dev_open(AUDIO_FLAG_REPLAY);
-	RomFileSeek(file, 0, SEEK_SET);
+	data_size = info->data_block.data_size;
 
-    while (1)
+    while (data_size > 0)
     {
         int length;
 
         /* 从文件系统读取 wav 文件的音频数据 */
+#ifdef ROMFILE_ADUIO
         length = RomFileRead(file, buffer, BUFSZ);
+#else
+		length = ff_fread(buffer, 1, BUFSZ, file);
+#endif
 
         if (length <= 0)
             break;
 
         /* 向 Audio 设备写入音频数据 */
         audio_dev_write(audio, buffer, length);
+		data_size -= length;
     }
 
     /* 关闭 Audio 设备 */
     audio_dev_close(audio);
 
 __exit:
-
     if (file)
+#ifdef ROMFILE_ADUIO
         RomFileClose(file);
+#else
+		ff_fclose(file);
+#endif
 
     if (buffer)
         vPortFree(buffer);