Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GpioBusInOut.cpp
00001 #include "GpioBusInOut.h" 00002 00003 GpioBusInOut::GpioBusInOut( 00004 CompGpioExp &gpiop, 00005 GpioPinName p0, GpioPinName p1, GpioPinName p2, GpioPinName p3, 00006 GpioPinName p4, GpioPinName p5, GpioPinName p6, GpioPinName p7, 00007 GpioPinName p8, GpioPinName p9, GpioPinName p10, GpioPinName p11, 00008 GpioPinName p12, GpioPinName p13, GpioPinName p14, GpioPinName p15 ) 00009 : gpio_p( &gpiop ) 00010 { 00011 GpioPinName pins[16] = { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15 }; 00012 init( gpiop, pins ); 00013 } 00014 00015 GpioBusInOut::GpioBusInOut( CompGpioExp &gpiop, GpioPinName pins[16] ) 00016 { 00017 init( gpiop, pins ); 00018 } 00019 00020 void GpioBusInOut::init( CompGpioExp &gpiop, GpioPinName pins[16] ) 00021 { 00022 for ( int i = 0; i < 16; i++ ) 00023 pin_list[ i ] = pins[ i ]; 00024 00025 mask_bits = ~(make_bitpattern( 0xFFFF )); 00026 } 00027 00028 GpioBusInOut::~GpioBusInOut() 00029 { 00030 } 00031 00032 void GpioBusInOut::write( int value ) 00033 { 00034 int bitpattern; 00035 00036 bitpattern = make_bitpattern( value ); 00037 gpio_p->write_with_mask( bitpattern, mask_bits ); 00038 } 00039 00040 int GpioBusInOut::make_bitpattern( int value ) 00041 { 00042 int bit_pattern = 0; 00043 00044 for ( int i = 0; i < 16; i++ ) 00045 bit_pattern |= (pin_list[ i ] != X_NC) ? ((value >> i) & 0x1) << pin_list[ i ] : 0x0; 00046 00047 return ( bit_pattern ); 00048 } 00049 00050 int GpioBusInOut::read( void ) 00051 { 00052 int r; 00053 int v = 0; 00054 00055 r = gpio_p->read(); 00056 00057 for ( int i = 0; i < 16; i++ ) 00058 v |= (pin_list[ i ] != X_NC) ? ((r >> pin_list[ i ]) & 0x1) << i : 0x0; 00059 00060 return v; 00061 } 00062 00063 void GpioBusInOut::output( void ) 00064 { 00065 gpio_p->configure_with_mask( 0x0, mask_bits ); 00066 } 00067 00068 void GpioBusInOut::input( void ) 00069 { 00070 gpio_p->configure_with_mask( ~0x0, mask_bits ); 00071 } 00072 00073 GpioBusInOut& GpioBusInOut::operator=( int rhs ) 00074 { 00075 write( rhs ); 00076 return *this; 00077 } 00078 00079 GpioBusInOut& GpioBusInOut::operator=( GpioBusInOut& rhs ) 00080 { 00081 write(rhs.read()); 00082 return *this; 00083 } 00084 00085 00086 GpioBusInOut::operator int( void ) 00087 { 00088 return( read() ); 00089 }
Generated on Tue Jul 12 2022 14:15:36 by
