- /*
- *******************************************************************
- * file:sc5020b.c
- *
- * func:sc5020b sound chip driver
- *
- * time:2017.03.01
- *
- * auth:lzx
- *******************************************************************
- */
- /*file*/
- #include"is32u320a.h" //the define of is32u320a register address
- #include"sc5020b.h" //the extern interface
- #include"is32u320a_gpio.h" //the func of io_config library
- /*flag*/
- #define G_SC5020B_BUSY_DIRECTION GPIO33 //use GPIO33 to be the sc5020b_busy_direction
- #define G_SC5020B_SDA_DIRECTION GPIO34 //use GPIO34 to be the sc5020b_sda_direction
- #define G_SC5020B_BUSY_IS_NOBUSY GPIODATA2&0X01 //make sure G_SC5020B_BUSY is busy or not
- /*
- *************************************
- * name:void sc5020b_io_initial()
- *
- * func:initiate the sc5020b_io
- *
- * time:2017.03.01
- *
- * auth:lzx
- *************************************
- */
- void sc5020b_io_initial(void)
- {
- SetGpioXIn(G_SC5020B_BUSY_DIRECTION); //G_SC5020B_BUSY is an input
- SetGpioXOut(G_SC5020B_SDA_DIRECTION); //G_SC5020B_SDA is an output
- }
- /*
- *************************************
- * name:void sc5020b_waitbusy(void)
- *
- * func:wait until sc5020b free
- *
- * time:2017.03.01
- *
- * auth:lzx
- *************************************
- */
- void sc5020b_waitbusy(void)
- {
- unsigned int times;
- for(times=0;times<50;times++) //the max time is 5 seconds,circle will be ended once more than max time
- {
- //sc5020b_delayms(100); //the time gap between each sound segment must be more than 100ms
- if(G_SC5020B_BUSY_IS_NOBUSY) break; //when G_SC5020B_BUSY is free,the chip can be sent commond
- }
- }
- /*
- *************************************
- * name:sc5020b_sendcommand(u8 dat)
- *
- * func:send command to sc5020b
- *
- * time:2017.03.01
- *
- * auth:lzx
- *************************************
- */
- void sc5020b_sendcommand(unsigned char dat)
- {
- char temp; //be used to make sure the each bit value of dat
- sc5020b_waitbusy(); //wait until sc5020b free,static wait time is 100ms
- //sc5020b_delayms(5); //wait for 5 micro second
- for(temp=0;temp<8;temp++)
- {
- SetGpioXHigh(G_SC5020B_SDA_DIRECTION); //pull up the G_SC5020B_SDA
- if(dat&0x01)
- { //send 1:high/low=3:1
- //sc5020b_delayus(1500);//delay1500us
- SetGpioXLow(G_SC5020B_SDA_DIRECTION);
- //sc5020b_delayus(500); //delay500us
- }
- else
- { //send 0:high/low=1:3
- //sc5020b_delayus(500); //delay500us
- SetGpioXLow(G_SC5020B_SDA_DIRECTION);
- //sc5020b_delayus(1500);//delay1500us
- }
- dat>>=1;
- }
- }
复制代码 |