原创 load a plugin for VS1053

2011-12-6 16:17 1498 17 17 分类: MCU/ 嵌入式


//--------------------------------
// load a plugin
// 1 Read register address number addr and repeat number n;
// 2 if (n & 0x8000u),write the next word n times to register addr;
// 3.Else write next n words to register addr;
// 4.continue until array has been exhausted.
//---------------------------------
void LoadUserCode(void)
{
int i = 0;
unsigned int addr, n, val;
unsigned char valh,vall;
 i =sizeof(plugin[0]);
 
while (i<sizeof(plugin)/sizeof(plugin[0]))
 {
     addr = plugin[i++];
    n = plugin[i++];
    if (n & 0x8000U)
  { /* RLE run, replicate n samples */
       n &= 0x7FFF;
       val = plugin[i++];
  valh = (val&0xff00) >>8;
  vall = val&0x00ff;
       while (n--)
   {
   Vs1053WriteRegister(addr,valh,vall);
          }
      }
 else
   {           /* Copy run, copy n samples */
       while (n--)
   {
          val = plugin[i++];
   valh = (val&0xff00) >>8;
   vall = val&0x00ff;
   Vs1053WriteRegister(addr,valh,vall);
          }
      }
   }
}

文章评论0条评论)

登录后参与讨论
我要评论
0
17
关闭 站长推荐上一条 /2 下一条