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

Post Reply
Khem
Posts: 26
Joined: Sun Feb 18, 2018 2:11 pm
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2
Location: San Jose, CA, US
Contact:

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

Unread post by 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

User avatar
tobetter
Posts: 2581
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Contact:

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

Unread post by 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?

Khem
Posts: 26
Joined: Sun Feb 18, 2018 2:11 pm
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2
Location: San Jose, CA, US
Contact:

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

Unread post by 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.

User avatar
tobetter
Posts: 2581
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Contact:

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

Unread post by 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 524 times
GPIO_SW1.png
GPIO_SW1.png (630.83 KiB) Viewed 524 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.

Khem
Posts: 26
Joined: Sun Feb 18, 2018 2:11 pm
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2
Location: San Jose, CA, US
Contact:

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

Unread post by 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 ?

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

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

Unread post by 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/bl ... dc2.h#L120

Add the following code to the linked source and try it.

Code: Select all

#define CONFIG_CMD_SARADC		1 


Khem
Posts: 26
Joined: Sun Feb 18, 2018 2:11 pm
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2
Location: San Jose, CA, US
Contact:

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

Unread post by 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/bl ... dc2.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.

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

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

Unread post by 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#

Khem
Posts: 26
Joined: Sun Feb 18, 2018 2:11 pm
languages_spoken: english, hindi, german
ODROIDs: Odroid-C2
Location: San Jose, CA, US
Contact:

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

Unread post by 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.

Post Reply

Return to “3.5inch LCD Shield”

Who is online

Users browsing this forum: No registered users and 1 guest