51 unsigned int frequency = 1 * bmptk::MHz
55 enum { type = type_spi_bus };
58 ( (
int)sclk_extern::type == bmptk::type_port_out )
59 | ( (
int)sclk_extern::type == bmptk::type_pin_in_out )
60 | ( (
int)sclk_extern::type == bmptk::type_pin_oc ),
61 "sclk must be a port_out, pin_in_out or a pin_oc"
64 ( (
int)mosi_extern::type == bmptk::type_pin_out )
65 | ( (
int)mosi_extern::type == bmptk::type_pin_in_out )
66 | ( (
int)mosi_extern::type == bmptk::type_pin_oc ),
67 "mosi must be a pin_out, pin_in_out or a pin_oc"
70 ( (
int)miso_extern::type == bmptk::type_pin_in )
71 | ( (
int)miso_extern::type == bmptk::type_pin_in_out )
72 | ( (
int)miso_extern::type == bmptk::type_pin_oc ),
73 "miso must be a pin_out, pin_in_out or a pin_oc"
88 epoch +=
bmptk::s / ( 2 * frequency );
146 static const bool cpha = ( mode & 0x01 ) != 0;
147 static const bool cpol = ( mode & 0x02 ) != 0;
150 ( (
int)bus::type == bmptk::type_spi_bus ),
151 "bus must be a spi bus"
155 ( (
int)ss_extern::type == bmptk::type_pin_out )
156 | ( (
int)ss_extern::type == bmptk::type_pin_in_out )
157 | ( (
int)ss_extern::type == bmptk::type_pin_oc ),
158 "ss must be a pin_out, pin_in_out or a pin_oc"
164 static unsigned char byte_in_out(
169 for(
int i = 0; i < 8; i++ ){
175 bus::mosi::set( out & 0x80 );
178 bus::sclk::set( ! cpol );
179 if( bus::miso::get() ){
184 bus::sclk::set( cpol );
188 bus::sclk::set( ! cpol );
191 bus::mosi::set( out & 0x80 );
192 bus::sclk::set( cpol );
195 if( bus::miso::get() ){
207 enum { type = type_spi_channel };
224 unsigned char *input,
225 unsigned char *output,
228 bus::sclk::set( cpol );
232 unsigned char in, out = 0;
236 in = byte_in_out( out );
247 unsigned char *input,
255 unsigned char *output,