Browse Source

backup vocoder

master
zhaijunyuan 5 years ago
parent
commit
a778b05b75
  1. 4
      Makefile
  2. 2
      lib/lib.mk
  3. 1
      lib/spi.c
  4. 94
      targets/xc_ppf1901/_i2c.c
  5. 7
      targets/xc_ppf1901/_i2c.h
  6. 6
      targets/xc_ppf1901/lmk.c
  7. 65
      targets/xc_ppf1901/main.c
  8. 67
      targets/xc_ppf1901/max31730.c
  9. 10
      targets/xc_ppf1901/max31730.h
  10. 22
      targets/xc_ppf1901/max6884.c
  11. 8
      targets/xc_ppf1901/max6884.h
  12. 2
      targets/xc_ppf1901/target.h
  13. 2
      targets/xc_ppf1901/target.mk

4
Makefile

@ -77,7 +77,7 @@ CFLAGS += $(debug_flags)
LDFLAGS += -L$(scripts_dir)
LDFLAGS += -Xlinker --gc-sections
LDFLAGS += -Xlinker --print-memory-usage
LDFLAGS += -Xlinker -nostdlib
LDFLAGS += -Xlinker -nostdlib
LDFLAGS += -Xlinker --sort-section=alignment -mcpu=cortex-m4 $(FP_FLAGS)
ROMBASE ?= 0x08000000
@ -172,7 +172,7 @@ $(BINARY).elf: | $(link_script)
$(BINARY).elf : $(firmware_objs)
@echo "linking $@"
@$(CC) $(LDFLAGS) -Wl,-Map="$@.map" -T $(link_script) $(specs) $^ -o $@
@$(CC) $(LDFLAGS) -Wl,-Map="$@.map" -T $(link_script) -u_printf_float $(specs) $^ -o $@
@$(SIZE) -Bd $@
iap.elf : $(iap_objs)

2
lib/lib.mk

@ -3,7 +3,6 @@ TARGET_CFLAGS += -I$(lib_dir)
lib_srcs += \
$(lib_dir)/gcc_stubs.c \
$(lib_dir)/tick.c \
$(lib_dir)/printf.c \
$(lib_dir)/fifo.c \
$(lib_dir)/cmd.c \
$(lib_dir)/commands.c \
@ -31,6 +30,7 @@ lib_srcs += \
$(lib_dir)/serial_ymodem.c \
$(lib_dir)/stdio_ymodem.c \
$(lib_dir)/sdio_sd.c \
$(lib_dir)/printf.c \
lib_objs = $(lib_srcs:.c=.o)

1
lib/spi.c

@ -1,3 +1,4 @@
#include <stddef.h>
#include <assert.h>
#include "stm32f4xx.h"
#include "gpio.h"

94
targets/xc_ppf1901/_i2c.c

@ -71,3 +71,97 @@ int i2c_read(uint8_t slv_addr, uint8_t *buf, uint32_t count)
i2c_stop(_i2c);
return count;
}
int i2c730_read(uint8_t slv_addr, uint8_t reg, signed char *buf, uint32_t count)
{
i2c_start(_i2c);
i2c_send_byte(_i2c, (slv_addr << 1));
if(i2c_wait_ack(_i2c))
{
i2c_stop(_i2c);
printf("address no ack\r\n");
return -1;
}
i2c_send_byte(_i2c, reg);
if(i2c_wait_ack(_i2c))
{
i2c_stop(_i2c);
return -1;
}
i2c_start(_i2c);
i2c_send_byte(_i2c,(slv_addr << 1) | 0x1);
if(i2c_wait_ack(_i2c))
{
i2c_stop(_i2c);
return -1;
}
for(int i=0; i<count; i++)
{
buf[i] = i2c_recv_byte(_i2c);
if(i == (count - 1))
i2c_nack(_i2c);
else
i2c_ack(_i2c);
}
i2c_stop(_i2c);
return count;
}
int i2c730_write(uint8_t slv_addr, uint8_t reg, uint8_t data, uint32_t count)
{
//int i;
i2c_start(_i2c);
i2c_send_byte(_i2c, (slv_addr << 1));
if(i2c_wait_ack(_i2c)) {
i2c_stop(_i2c);
printf("address no ack\r\n");
return -1;
}
#if 1
i2c_send_byte(_i2c,reg);
if(i2c_wait_ack(_i2c)) {
printf("first byte no ack\r\n");
i2c_stop(_i2c);
return -1;
}
i2c_send_byte(_i2c,data);
if(i2c_wait_ack(_i2c)) {
printf("first byte no ack\r\n");
i2c_stop(_i2c);
return -1;
}
#else
i2c_send_byte(_i2c,reg);
if(i2c_wait_ack(_i2c)) {
printf("first byte no ack\r\n");
i2c_stop(_i2c);
return -1;
}
#endif
i2c_stop(_i2c);
return count;
}
int i2c6884_read(uint8_t slv_addr, uint8_t reg, signed char *buf, uint32_t count)
{
return i2c730_read(slv_addr, reg, buf, count);
}
int i2c6884_write(uint8_t slv_addr, uint8_t reg, uint8_t data, uint32_t count)
{
return i2c730_write(slv_addr, reg, data, count);
}

7
targets/xc_ppf1901/_i2c.h

@ -6,6 +6,13 @@
int i2c_read(uint8_t slc_addr, uint8_t *buf, uint32_t count);
int i2c_write(uint8_t slc_addr, uint8_t *data, uint32_t count);
int i2c730_read(uint8_t slc_addr, uint8_t reg, signed char *buf, uint32_t count);
int i2c730_write(uint8_t slc_addr, uint8_t reg, uint8_t data, uint32_t count);
int i2c6884_read(uint8_t slv_addr, uint8_t reg, signed char *buf, uint32_t count);
int i2c6884_write(uint8_t slv_addr, uint8_t reg, uint8_t data, uint32_t count);
void i2c_init(i2c_t i2c);
#endif

6
targets/xc_ppf1901/lmk.c

@ -416,9 +416,9 @@ int lmk_init(int cs)
lmk_write(cs, 329, 51);
dwt_wait_ms(10);
val = lmk_read(cs, 3);
printf("val = %x, cs = %d\n",val,cs);
printf("val = %x, cs = %d\r\n",val,cs);
if(val != 0x6) {
printf("lmk04828 device error\n");
printf("lmk04828 device error\r\n");
// return -1;
}
if(cs == 0) {
@ -442,7 +442,7 @@ int lmk_init(int cs)
val = lmk_read(cs, 387);
if(val != 2) {
printf("lmk reg 0x183 expect 2, but get %d \n", val);
printf("lmk reg 0x183 expect 2, but get %d \r\n", val);
return -2;
}

65
targets/xc_ppf1901/main.c

@ -10,6 +10,10 @@
#include "_i2c.h"
#include "lmk.h"
#include "dwt.h"
#include "tick.h"
#include "max31730.h"
#include "max6884.h"
i2c_t _i2c;
@ -31,16 +35,23 @@ int send()
int main()
{
signed char data_6884[8];
// float data[8];
// signed char ID;
uint64_t prev = 0, now;
gpio_init(PH4, GPIO_OUTPUT);
gpio_init(PB0, GPIO_OUTPUT);
i2s_spi_fmt_s i2s_spi_cfg;
/*
* recovery from bad image.
*/
/*
* recovery from bad image.
*/
_i2c = i2c_new(PB8, PB9, 400000);
//eeprom_init_with_i2c(_i2c, I2C_ADDR_EEPROM, 0);
iwdg_set_period_ms(1000);
//iwdg_start();
iwdg_set_period_ms(1000);
//iwdg_start();
i2c_init(_i2c);
@ -49,15 +60,15 @@ int main()
i2s_spi_cfg.endian = 0;
i2s_init(&i2s_spi_cfg);
printf("build: %s (%s)\r\n", __DATE__, __TIME__);
printf("build: %s (%s)\r\n", __DATE__, __TIME__);
bkp_sram_write(MAGIC_POS, MAGIC_APP);
bkp_sram_write(MAGIC_POS, MAGIC_APP);
dwt_wait_ms(100);
if(lmk_init(0) == 0)
printf("cs 0 init success!!!\n");
printf("cs 0 init success!!!\r\n");
// i2s_clear();
// i2s_clear();
dwt_wait_ms(100);
gpio_clear(PB0);
@ -67,17 +78,43 @@ int main()
dwt_wait_ms(100);
gpio_set(PB0);
i2s_init(&i2s_spi_cfg);
dwt_wait_ms(1000);
if(lmk_init(1) == 0)
printf("cs 1 init success!!!\n");
printf("cs 1 init success!!!\r\n");
printf("running\r\n...............................\r\n> ");
printf("running\r\n...............................\r\n> ");
// max31730_init(0x4f);
// max31730_init(0x1c);
gpio_clear(PH4);
dwt_wait_ms(100);
gpio_set(PH4);
max6884_init();
while (1) {
// send();
// send();
now = millis();
if ((now - prev) > 100) {
#if 0
//data[0] = max31730_read_local(0x4f);
//i2c730_read(0x4f, 0x50, &ID, 1);
data[0] = max31730_read_local(0x1c);
i2c730_read(0x1c, 0x50, &ID, 1);
printf("max31730 = %x\r\n",ID);
printf("max31730 = %f\r\n",data[0]);
for(int i=1; i<4; i++)
{
data[i] = max31730_read_temperature(0x1c,i);
printf("max31730_temperature%d = %f\r\n",i,data[i]);
}
#else
data_6884[0] = max6884_read(0x24);
printf("max6884 = %x\r\n",data_6884[0]);
#endif
prev = now;
}
cmd_loop();
iwdg_reset();
iwdg_reset();
}
return 0;
}

67
targets/xc_ppf1901/max31730.c

@ -0,0 +1,67 @@
#include <stdio.h>
#include "_i2c.h"
#include "dwt.h"
void max31730_init(uint8_t addr)
{
i2c730_write(addr, 0x13, 0x52, 1);
dwt_wait_ms(50);
i2c730_write(addr, 0x12, 0x00, 1);
i2c730_write(addr, 0x13, 0x12, 1);
i2c730_write(addr, 0x15, 0x00, 1);
i2c730_write(addr, 0x17, 0x00, 1);
i2c730_write(addr, 0x18, 0x00, 1);
i2c730_write(addr, 0x19, 0x00, 1);
i2c730_write(addr, 0x35, 0x0F, 1);
}
float max31730_read_temperature(uint8_t addr, int device_num)
{
uint8_t T_MSB = 0x00, T_LSB = 0x00;
signed char data_M, data_L;
float temp,data_F;
switch(device_num)
{
case 1:
T_MSB = 0x02;
T_LSB = 0x03;
break;
case 2:
T_MSB = 0x04;
T_LSB = 0x05;
break;
case 3:
T_MSB = 0x06;
T_LSB = 0x07;
break;
default:
break;
}
i2c730_read(addr, T_MSB, &data_M, 1);
i2c730_read(addr, T_LSB, &data_L, 1);
data_F = ((data_L >> 4) & 0x01) * 0.0625 + ((data_L >> 5) & 0x01) * 0.125 + ((data_L >> 6) & 0x01) * 0.25 + ((data_L >> 7) & 0x01) * 0.5;
temp = data_M + data_F + 64;
return temp;
}
float max31730_read_local(uint8_t addr)
{
uint8_t T_MSB = 0x00, T_LSB = 0x01;
signed char data_M, data_L;
float temp,data_F;
i2c730_read(addr, T_MSB, &data_M, 1);
i2c730_read(addr, T_LSB, &data_L, 1);
printf("data_M = %d, data_L = %d\r\n",data_M, data_L);
data_F = ((data_L >> 4) & 0x01) * 0.0625 + ((data_L >> 5) & 0x01) * 0.125 + ((data_L >> 6) & 0x01) * 0.25 + ((data_L >> 7) & 0x01) * 0.5;
temp = data_M + data_F + 64;
return temp;
}

10
targets/xc_ppf1901/max31730.h

@ -0,0 +1,10 @@
#ifndef MAX31730_H
#define MAX31730_H
int max31730_read(uint8_t addr, uint8_t reg, uint8_t *buf, int count);
void max31730_init(uint8_t addr);
float max31730_read_temperature(uint8_t addr, int device_num);
float max31730_read_local(uint8_t addr);
#endif

22
targets/xc_ppf1901/max6884.c

@ -0,0 +1,22 @@
#include <stdio.h>
#include "_i2c.h"
#include "max6884.h"
#define ADDR 0x52
void max6884_init()
{
i2c6884_write(ADDR,0x16,0x20, 1);
i2c6884_write(ADDR,0x11,0x00, 1);
i2c6884_write(ADDR,0x12,0x00, 1);
i2c6884_write(ADDR,0x13,0x00, 1);
i2c6884_write(ADDR,0x14,0x00, 1);
i2c6884_write(ADDR,0x15,0x00, 1);
}
signed char max6884_read(uint8_t reg)
{
signed char buf;
i2c6884_read(ADDR, reg, &buf, 1);
return buf;
}

8
targets/xc_ppf1901/max6884.h

@ -0,0 +1,8 @@
#ifndef MAX6884_H
#define MAX6884_H
void max6884_init();
signed char max6884_read(uint8_t reg);
#endif

2
targets/xc_ppf1901/target.h

@ -10,7 +10,7 @@
#define TICKS_PERIOD (2) /* mill seconds */
#define CONSOLE_BAUDRATE (115200)
#define TARGET_HEAP_SIZE (0x200000)
#define TARGET_HEAP_SIZE (0x1000)
#define I2C_ADDR_EEPROM (0x50)
#define I2C_ADDR_MAX6884 (0x28)

2
targets/xc_ppf1901/target.mk

@ -18,6 +18,8 @@ vocoder_srcs := \
$(target_dir)/_i2c.c \
$(target_dir)/i2s.c \
$(target_dir)/lmk.c \
$(target_dir)/max31730.c \
$(target_dir)/max6884.c \
$(target_dir)/main.c
iap_srcs := \

Loading…
Cancel
Save