Using the A/D analog inputs from u-boot on C2

Moderators: odroid, mdrjr

Using the A/D analog inputs from u-boot on C2

Unread postby Khem » Wed Oct 03, 2018 3:00 pm

I would like to use the buttons on 3.5 inch LCD shield to define some boot actions. If someone has already done that or can share some thoughts on how to get this done in u-boot would be much appreciated
Khem
 
Posts: 24
Joined: Sun Feb 18, 2018 2:11 pm
Location: San Jose, CA, US
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2

Re: Using the A/D analog inputs from u-boot on C2

Unread postby tobetter » Wed Oct 03, 2018 3:33 pm

Khem wrote:I would like to use the buttons on 3.5 inch LCD shield to define some boot actions. If someone has already done that or can share some thoughts on how to get this done in u-boot would be much appreciated

What's the use case you want?
User avatar
tobetter
 
Posts: 2557
Joined: Mon Feb 25, 2013 10:55 am
Location: Paju, South Korea
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1

Re: Using the A/D analog inputs from u-boot on C2

Unread postby Khem » Fri Oct 05, 2018 2:46 pm

tobetter wrote:
Khem wrote:I would like to use the buttons on 3.5 inch LCD shield to define some boot actions. If someone has already done that or can share some thoughts on how to get this done in u-boot would be much appreciated

What's the use case you want?


I would like to read one of switch or two, if they are pressed when powered on, then boot into a different partition. So I can set the rootfs into uboot env before proceeding.
Khem
 
Posts: 24
Joined: Sun Feb 18, 2018 2:11 pm
Location: San Jose, CA, US
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2

Re: Using the A/D analog inputs from u-boot on C2

Unread postby tobetter » Fri Oct 05, 2018 4:01 pm

Khem wrote:
tobetter wrote:
Khem wrote:I would like to use the buttons on 3.5 inch LCD shield to define some boot actions. If someone has already done that or can share some thoughts on how to get this done in u-boot would be much appreciated

What's the use case you want?


I would like to read one of switch or two, if they are pressed when powered on, then boot into a different partition. So I can set the rootfs into uboot env before proceeding.

You can consider allocating a GPIO on pin header or you can use another one sw1. This switch was designed initially to make ODROID-C2 can run UMS on boot when it turns on, but it's deprecated and you can use it's soldering pad.
GPIO_BIT5.png
GPIO_BIT5.png (25.28 KiB) Viewed 459 times

GPIO_SW1.png
GPIO_SW1.png (630.83 KiB) Viewed 459 times


You can use this commit if you like to use the switch.
https://github.com/hardkernel/u-boot/co ... ff=unified

Even if you want to use another GPIO on pin header, the way what you have to do in the code is very similar.
User avatar
tobetter
 
Posts: 2557
Joined: Mon Feb 25, 2013 10:55 am
Location: Paju, South Korea
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1

Re: Using the A/D analog inputs from u-boot on C2

Unread postby Khem » Wed Oct 10, 2018 7:06 am

it seems the LCD buttons come via pin 40 which seems to be dedicated ADC pin. Is there a way to read that in uboot ?
Khem
 
Posts: 24
Joined: Sun Feb 18, 2018 2:11 pm
Location: San Jose, CA, US
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2

Re: Using the A/D analog inputs from u-boot on C2

Unread postby cap00k » Wed Oct 10, 2018 2:19 pm

Hi, Khem
I have not tried it, but CMD_SARADC is not currently enabled in u-boot.

https://github.com/hardkernel/u-boot/blob/95264d19d04930f67f10f162df70de447659329d/include/configs/odroidc2.h#L120

Add the following code to the linked source and try it.
Code: Select all
#define CONFIG_CMD_SARADC      1

cap00k
 
Posts: 67
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID

Re: Using the A/D analog inputs from u-boot on C2

Unread postby Khem » Thu Oct 11, 2018 12:27 pm

cap00k wrote:Hi, Khem
I have not tried it, but CMD_SARADC is not currently enabled in u-boot.

https://github.com/hardkernel/u-boot/blob/95264d19d04930f67f10f162df70de447659329d/include/configs/odroidc2.h#L120

Add the following code to the linked source and try it.
Code: Select all
#define CONFIG_CMD_SARADC      1



yes that helped to get adc driver enabled. Now need to make sure what values It reads and how to find which channel to select to read the values.
Khem
 
Posts: 24
Joined: Sun Feb 18, 2018 2:11 pm
Location: San Jose, CA, US
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2

Re: Using the A/D analog inputs from u-boot on C2

Unread postby cap00k » Thu Oct 11, 2018 3:03 pm

At the uboot prompt, type 'saradc help'
<channel> look at hardware connections.

Code: Select all
odroidc2#saradc help
saradc - saradc sub-system

Usage:
saradc saradc open <channel>            - open a SARADC channel
saradc close    - close the SARADC
saradc getval   - get the value in current channel
saradc get_in_range <min> <max> - return 0 if current value in the range of current channel

odroidc2#
cap00k
 
Posts: 67
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID

Re: Using the A/D analog inputs from u-boot on C2

Unread postby Khem » Fri Oct 12, 2018 5:44 am

cap00k wrote:At the uboot prompt, type 'saradc help'
<channel> look at hardware connections.

Code: Select all
odroidc2#saradc help
saradc - saradc sub-system

Usage:
saradc saradc open <channel>            - open a SARADC channel
saradc close    - close the SARADC
saradc getval   - get the value in current channel
saradc get_in_range <min> <max> - return 0 if current value in the range of current channel

odroidc2#


yes it works. Now I want to code the logic in the ini file to detect if a switch is pressed during boot.
Khem
 
Posts: 24
Joined: Sun Feb 18, 2018 2:11 pm
Location: San Jose, CA, US
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2


Return to 3.5inch LCD Shield

Who is online

Users browsing this forum: No registered users and 8 guests