@@ -297,6 +297,7 @@ func New(bus drivers.SPI, csPin, ackPin, gpio0Pin, resetPin machine.Pin) *Device
297297func (d * Device ) Configure () {
298298
299299 net .UseDriver (d .NewDriver ())
300+ pinUseDevice (d )
300301
301302 d .CS .Configure (machine.PinConfig {Mode : machine .PinOutput })
302303 d .ACK .Configure (machine.PinConfig {Mode : machine .PinInput })
@@ -689,6 +690,23 @@ func (d *Device) StartScanNetworks() (uint8, error) {
689690 return d .getUint8 (d .req0 (CmdStartScanNetworks ))
690691}
691692
693+ func (d * Device ) PinMode (pin uint8 , mode uint8 ) error {
694+ _ , err := d .req2Uint8 (CmdSetPinMode , pin , mode )
695+ return err
696+ }
697+
698+ func (d * Device ) DigitalWrite (pin uint8 , value uint8 ) error {
699+ _ , err := d .req2Uint8 (CmdSetDigitalWrite , pin , value )
700+ return err
701+ }
702+
703+ func (d * Device ) AnalogWrite (pin uint8 , value uint8 ) error {
704+ _ , err := d .req2Uint8 (CmdSetAnalogWrite , pin , value )
705+ return err
706+ }
707+
708+ // ------------- End of public device interface ----------------------------
709+
692710func (d * Device ) getString (l uint8 , err error ) (string , error ) {
693711 if err != nil {
694712 return "" , err
@@ -773,6 +791,14 @@ func (d *Device) reqUint8(cmd uint8, data uint8) (l uint8, err error) {
773791 return d .waitRspCmd1 (cmd )
774792}
775793
794+ // req2Uint8 sends a command to the device with two uint8 parameters
795+ func (d * Device ) req2Uint8 (cmd , p1 , p2 uint8 ) (l uint8 , err error ) {
796+ if err := d .sendCmdPadded2 (cmd , p1 , p2 ); err != nil {
797+ return 0 , err
798+ }
799+ return d .waitRspCmd1 (cmd )
800+ }
801+
776802// reqStr sends a command to the device with a single string parameter
777803func (d * Device ) reqStr (cmd uint8 , p1 string ) (uint8 , error ) {
778804 if err := d .sendCmdStr (cmd , p1 ); err != nil {
@@ -834,6 +860,18 @@ func (d *Device) sendCmdPadded1(cmd uint8, data uint8) error {
834860 return nil
835861}
836862
863+ func (d * Device ) sendCmdPadded2 (cmd , data1 , data2 uint8 ) error {
864+ defer d .spiChipDeselect ()
865+ if err := d .waitForChipSelect (); err != nil {
866+ return err
867+ }
868+ l := d .sendCmd (cmd , 1 )
869+ l += d .sendParam8 (data1 , false )
870+ l += d .sendParam8 (data2 , true )
871+ d .SPI .Transfer (dummyData )
872+ return nil
873+ }
874+
837875func (d * Device ) sendCmdStr (cmd uint8 , p1 string ) (err error ) {
838876 defer d .spiChipDeselect ()
839877 if err := d .waitForChipSelect (); err != nil {
0 commit comments