Part 3: LEDs, Buttons and Relays
Finding the connections
With all the information gathered so far, it shouldn’t be too hard to find out, how the LEDs, the relay and the button are connected to the CPU. Most probably, they are all connected to some GPIO port.
According to the data sheet, the MT6788 has 96 GPIO ports and the GPIO control registers start at address 0x10000600.
We let the device boot regulary and then switch to the CLI’s
Playing with the
reg w and
reg r commands quickly gives us
the following information:
- The relay is connected to GPIO 32
- The red LED is connected to GPIO 33
- The green LED is connected to GPIO 34
- The button is connected to GPIO 35
So, the following command switches the relay:
reg w 10000634 1 # Switch relay on reg w 10000644 1 # Switch relay off
and the following command switches the LEDs:
reg w 10000644 6 # Switch both LEDs on reg w 10000634 6 # Switch both LEDs off
and bit 3 from the following command tells us, whether or not the button is currently pressed:
reg r 10000624 # bit 3 == 0 -> button pressed
You shouldn’t press the button too long: a four to five seconds press performs a factory reset of the device.
Note that the polarity for switching the relay and the LEDs is inverted, but this is a pure software feature, because the polarity of the GPIO ports can be configured.
Does this work from u-boot too?
Next step is to test this from a lower level, i.e. from the u-boot
command line. We can use the
mm commands to write to
the registers. Of course, the naive approach to just repeat the
commands from above doesn’t work: the SoC needs to be configured to
actually use the GPIOs. The MSS310 application does this, but u-boot
doesn’t (it does, however, configure the UART). We need to set the
following registers to make the GPIOs available:
0x10000064 -> 0x05550550 0x10000604 -> 0x00000007 # Configure bits 0..2 as output
Afterwards, we can control the LEDs and the relay from the u-boot command line.