I got past the 8-bits vs 16-bits issue and I was just listening to my first song on the si4703; Phil Collings I believe...
/*
si4703 begins reading from register upper register of 0x0A and reads
to 0x0F, then loops to 0x00. Since register 0x0A comes in first
we have to shuffle the array around a bit.
*/
si4703.prototype.readReg = function ( verb ) {
//this.i2c.writeTo( this.addr, 0 );
data = this.i2c.readFrom( this.addr, 32 );
for( var i=0; i<data.length; i+=2 )
{
bits = data [ i ] << 8;
bits |= data[ i+1 ];
reg = ( i < 12 ? i+(10-i/2) : (i/2)-6 );
this.registers[reg] = bits;
}
if( verb !== false )
this.printReg();
};
/*
Write the current 9 control registers (0x02 to 0x07) to the Si4703.
It's a little weird, you don't write an I2C addres, The Si4703 assumes
you are writing to 0x02 first, then increments.
*/
si4703.prototype.writeReg = function () {
bytes = [];
for( i=0x02; i<0x08; i++ )
{
var high = this.registers[ i ] >> 8;
var low = this.registers[ i ] & 0x00FF;
bytes.push(high, low);
}
this.i2c.writeTo( this.addr, bytes );
};
si4703.prototype.printReg = function () {
console.log( 'Register | Dec | Hex | Bits');
fill = String('.');
for( var i in this.r )
{
label = i;
dec = this.registers[ this.r[i] ];
hex = dec.toString(16);
bits = dec.toString(2);
console.log( label + fill.repeat(10-label.length ) + ' | ' +
dec + fill.repeat(6-String(dec).length) + ' | ' +
hex + fill.repeat(5-hex.length) + ' | ' +
fill.repeat(18-bits.length) + bits
);
}
console.log(" ");
};
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I got past the 8-bits vs 16-bits issue and I was just listening to my first song on the si4703; Phil Collings I believe...
This is working just fine:
So now onwards to an Espruino-port of the Arduino sketch!