53 enum { type = type_port_in };
56 enum { features = has_none };
80 static unsigned int get();
94 enum { type = type_port_out };
97 enum { features = has_none };
120 static void set(
unsigned int d );
135 enum { type = type_port_in_out };
138 enum { features = has_none };
166 static void set(
unsigned int d );
173 static unsigned int get();
188 enum { type = type_port_oc };
191 enum { features = has_none };
203 static void set(
unsigned int d );
210 static unsigned int get();
237 static void set(
unsigned int x ){}
238 static int n_pins(){
return 0; }
241 template<
typename arg_pin,
typename... tail_args >
242 struct port_out_from_pins< arg_pin, tail_args... > :
public port_out {
245 ( (
int)arg_pin::type == bmptk::type_pin_out )
246 | ( (
int)arg_pin::type == bmptk::type_pin_in_out )
247 | ( (
int)arg_pin::type == bmptk::type_pin_oc ),
248 "port_out_from_pins requires pin_out, pin_in_out or a pin_oc"
251 typedef port_out_from_pins< tail_args... > tail;
252 typedef pin_out_from< arg_pin > pin;
259 static void set(
unsigned int x ){
260 pin::set( x & 0x01 );
265 return tail::n_pins() + 1;
286 static unsigned int get(){
return 0; }
287 static int n_pins(){
return 0; }
290 template<
typename arg_pin,
typename... tail_args >
291 class port_in_from_pins< arg_pin, tail_args... > :
public port_in {
294 typedef port_in_from_pins< tail_args... > tail;
295 typedef pin_in_from< arg_pin > pin;
302 static unsigned int get(){
305 | pin::get() ? 0x01 : 0x00;
309 return tail::n_pins() + 1;
330 static unsigned int get(){
return 0; }
331 static void set(
unsigned int x ){}
332 static int n_pins(){
return 0; }
337 template<
typename arg_pin,
typename... tail_args >
338 class port_in_out_from_pins< arg_pin, tail_args... > :
public port_in_out {
341 typedef port_in_out_from_pins< tail_args... > tail;
342 typedef pin_in_out_from< arg_pin > pin;
349 static void set(
unsigned int x ){
350 pin::set( x & 0x01 );
354 static unsigned int get(){
357 | pin::get() ? 0x01 : 0x00;
361 pin::direction_set_input();
362 tail::direction_set_input();
366 pin::direction_set_output();
367 tail::direction_set_output();
371 return tail::n_pins() + 1;
392 static unsigned int get(){
return 0; }
393 static void set(
unsigned int x ){}
394 static int n_pins(){
return 0; }
397 template<
typename arg_pin,
typename... tail_args >
398 class port_oc_from_pins< arg_pin, tail_args... > :
public port_oc {
401 typedef port_oc_from_pins< tail_args... > tail;
402 typedef pin_oc_from< arg_pin > pin;
409 static void set(
unsigned int x ){
410 pin::set( x & 0x01 );
414 static unsigned int get(){
417 | pin::get() ? 0x01 : 0x00;
421 return tail::n_pins() + 1;
427 template<
typename port >
443 static void set(
unsigned int x );
450 template<
typename channel >
453 static unsigned int port_out_buffer;
455 static void port_out_flush(){
456 channel::set( port_out_buffer );
467 static void set(
bool x ){
469 port_out_buffer |= ( 0x01 << p );
471 port_out_buffer &= ~ ( 0x01 << p );
485 static void set(
unsigned int x ){
520 template <
typename channel >
530 static void set(
unsigned int x );
533 static unsigned int get();
540 template<
typename channel >
543 static unsigned int port_in_buffer;
544 static unsigned int port_out_buffer;
546 static void port_out_flush(){
547 channel::set( port_out_buffer );
550 static void port_in_refresh(){
551 port_in_buffer = channel::get();
562 static void set(
bool x ){
564 port_out_buffer |= ( 0x01 << p );
566 port_out_buffer &= ~ ( 0x01 << p );
573 return port_in_buffer &( 0x01 << p );
585 static void set(
unsigned int x ){
596 static unsigned int get(){
598 return port_in_buffer;
626 template <
typename channel >
628 template <
typename channel >
638 static unsigned int get();
645 template<
typename channel >
648 static unsigned int port_in_buffer;
650 static void port_in_refresh(){
651 port_in_buffer = channel::get();
664 return port_in_buffer &( 0x01 << p );
681 static unsigned int get(){
683 return port_in_buffer;
711 template <
typename channel >
721 static void set(
unsigned int x );
724 static unsigned int get();
730 static unsigned direction(
unsigned int x );
737 template<
typename channel >
740 static unsigned int port_in_buffer;
741 static unsigned int port_out_buffer;
742 static unsigned int port_direction_buffer;
744 static void port_out_flush(){
745 channel::set( port_out_buffer );
748 static void port_in_refresh(){
749 port_in_buffer = channel::get();
752 static void port_direction_flush(){
753 channel::direction( port_direction_buffer );
764 static void set(
bool x ){
766 port_out_buffer |= ( 0x01 << p );
768 port_out_buffer &= ~ ( 0x01 << p );
775 return port_in_buffer &( 0x01 << p );
779 port_direction_buffer &= ( 0x01 << p ) ^ -1;
780 port_direction_flush();
784 port_direction_buffer |= ( 0x01 << p );
785 port_direction_flush();
797 static void set(
unsigned int x ){
808 static unsigned int get(){
810 return port_in_buffer;
815 port_direction_buffer = 0;
816 port_direction_flush();
821 port_direction_buffer = 0 ^ -1;
822 port_direction_flush();
850 template <
typename channel >
852 template <
typename channel >
854 template <
typename channel >
866 template<
class port >
867 struct invert< port, type_port_out > :
public port {
868 static void set(
unsigned int x ){ port::set( x ^ -1 ); }
871 template<
class port >
872 struct invert< port, type_port_in > :
public port {
873 static unsigned int get(){
return port::get() ^ -1; }
876 template<
class port >
877 struct invert< port, type_port_in_out > :
public port {
878 static void set(
unsigned int x ){ port::set( x ^ -1 ); }
879 static unsigned int get(){
return port::get() ^ -1; }
881 template<
class port >
883 struct invert< port, type_port_oc > :
public port {
884 static void set(
unsigned int x ){ port::set( x ^ -1 ); }
885 static unsigned int get(){
return port::get() ^ -1; }