moved chip select from js to c