Walkthrough: Adding a feature to your Embedded Controller

Hey all! :wave:t2:

I just published a quick blog post detailing how I added an Fn lock light to my Laptop and how you could, too!

This is not intended to be a guide everyone goes out and follows; rather, I’m hoping to illustrate how you might approach firmware development, wayfinding, and thinking about the things that your laptop is capable of.

There isn’t a good story today for sharing EC patches, and the bar seems like it will be pretty high to get them into the official firmware (for sure, a feature that kills Caps Lock would not be acceptable!), but I’m hoping that this might serve as some groundwork that we can all collectively build on.

Oh, and if you brick your Laptop, probably don’t go to Framework’s support and ask them to replace it. Also, I offer no warranty. If you’re doing this on your daily driver, (1) whoa, gutsy! and (2) godspeed.

10 Likes

Great writing. I wonder if there is a way to fade or pulse the led when Fn-on, solid or different pattern if additional CapLock on.

1 Like

(Looks at own Forums avatar)

I passed out after reading this and needed a cigarette after I woke up.

Thank you! Thank you so much!

Edit: Could this be wired to the power button, for example, to go to a different colour, or to blink in a certain pattern?

1 Like

That’s actually an interesting idea. AFAICS, the power led can be made different colors (though I believe reading somewhere it’s not full RGB - blue is missing), so that could be an interesting indicator for FN lock.

Definitely possible! There’s a couple reasons I didn’t choose to do it for this post, however:

  1. The power button light is used in more places, and dealing with the state transitions and who owns the light at any given moment is pretty messy. It didn’t make good “101”-level content :slight_smile:
    • Incidentally, it’s a PWM light instead of a GPIO light and it has some special capabilities¹.
  2. Ah, what style would I choose? Blinking would be annoying, always flickering just at the edges of your sight. Red generally indicates that something is bad or broken, and the EC already uses it to indicate that the battery is too low to turn on. Green and amber are available!

It’s definitely a good follow-up!

¹ It uses the MEC’s support for a “blinking-breathing LED”, which is apparently drives the LED without the firmware’s involvement. Cool!

Step 2’s link to repo is incorrect. It should be https://github.com/FrameworkComputer/EmbeddedController
not
https://github.com/Framework/EmbeddedController

Thanks for catching that!

(I saw in my e-mail that you mentioned gpio_set_level and GPIO_CAP...; I decided to gloss over that by saying we’d “steal” the right parts from the existing caps lock code, but I do think it’s a good thing for you to call out. Thank you!)

The possibility to access the EC was one of the reasons I bought the Framework. I just didnt know where to start. Your tutorial just solved that and I want to thank you for that.

I’m currently stuck at Step 4, building the code. I have no prior experience with the make command. So I followed strictly the tutorial. I ran the make command in the ec directory that I cloned from github and got errors stating that some constants are undeclared:

We copied the constant CAPS_LED from another already existing function, so I dont understand where the error comes from. What needs to be done to resolve the errors?

1 Like

This might be an instance where my post isn’t very clear, thanks for bringing it up! You don’t need to introduce another copy of the hx20_8042_led_control function. None of the new code we’re adding should refer to CAPS_LED or caps_led_status, since that’s the stuff we’re trying to disable or get rid of.

I think I know what happened. The highlighting on this code block either doesn’t work or is not different from the other ones where I introduce new, to-be-written code. It might mislead folks into adding a copy of the entire function.

image

@DHowett, would you have the time to extend the tutorial to cover the following:
How to toggle between the default CAPS Lock LED behaviour and the modified behaviour via ECtool?

The highlighting on this code block either doesn’t work or is not different from the other ones where I introduce new, to-be-written code. It might mislead folks into adding a copy of the entire function.

It looks like all the other code that we add indeed. Additionally right before the screenshot it is stated that we can copy the code from Caps Lock. That convinced me to copy that aswell.

I deleted the copy of the function hx20_8042_led_control(). I get now a different error, which is even more confusing to me:
ec_make_error2

I’ll see what I can do. I may not have time to do that, but somebody from the community is of course welcome to write a followup! :slight_smile:

If you’re on Ubuntu or Debian, you’ll need to install the libftdi1-dev package. If you’ve got that, it may be related to the pkg-config error above; try installing the pkg-config package. If you’re on another distribution, you’ll need to figure out how to install pkg-config and the libftdi headers for that distribution.

Thanks for the feedback! I’ll work on the wording a little bit.