Giter Site home page Giter Site logo

GPIO implementation about linux-xtensa HOT 18 CLOSED

zap8600 avatar zap8600 commented on June 18, 2024
GPIO implementation

from linux-xtensa.

Comments (18)

zap8600 avatar zap8600 commented on June 18, 2024 2

So I did a bit of thinking, and I think I know how to use the GPIO now. I can use GPIO_ENABLE_REG to set the pin I want to output, then pull it high with GPIO_OUT_REG. I'm not sure when I'll be able to test my code, but I'm (sorta) confident in my code.

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024 1

would this work?

About that pattern: tell me if I'm wrong, but you can compile it, run it and see for yourself?

I mean, the human capacity is limited, it makes sense to ask humans the questions that the hardware cannot answer.

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024

I can't find the code

I believe there was no kernel code, but a userspace program that was writing registers directly.

from linux-xtensa.

zap8600 avatar zap8600 commented on June 18, 2024

I believe there was no kernel code, but a userspace program that was writing registers directly.

Do you still have the program?

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024

Do you still have the program?

It's devmem, part of busybox. See https://olimex.wordpress.com/2023/06/27/running-linux-with-kernel-6-3-on-open-source-hardware-board-with-esp32-s3/ for the use example.

from linux-xtensa.

zap8600 avatar zap8600 commented on June 18, 2024

It's devmem, part of busybox. See https://olimex.wordpress.com/2023/06/27/running-linux-with-kernel-6-3-on-open-source-hardware-board-with-esp32-s3/ for the use example.

What about in C code? I plan on trying to write a driver if I can figure out how.

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024

What about in C code?

Depends on how fancy/portable you want your code. You can just write data directly to the desired physical address from the userspace if you don't care at all.

I plan on trying to write a driver

Then it might be a good idea to take a look at other similar drivers.

from linux-xtensa.

zap8600 avatar zap8600 commented on June 18, 2024

Then it might be a good idea to take a look at other similar drivers.

Are there any similar drivers?

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024

A whole bunch.

from linux-xtensa.

zap8600 avatar zap8600 commented on June 18, 2024

Could we use the MMIO GPIO driver?

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024

IDK. Perhaps. Try and see?

from linux-xtensa.

zap8600 avatar zap8600 commented on June 18, 2024

What is the minimum for writing my own driver?

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024

What is the minimum for writing my own driver?

Minimum what? Minimum understanding: understanding the gpio driver structure and understanding the hardware.

from linux-xtensa.

zap8600 avatar zap8600 commented on June 18, 2024

Minimum what? Minimum understanding: understanding the gpio driver structure and understanding the hardware.

Minimum my driver needs to provide.

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024

IDK. I don't have any experience with the gpio subsystem whatsoever.

from linux-xtensa.

zap8600 avatar zap8600 commented on June 18, 2024

Tell me if I'm wrong, but each GPIO pin takes up 2 bytes in the MMIO, so GPIO0 is at 0x60004000, GPIO1 is at 0x60004004, etc. Is this right?

from linux-xtensa.

jcmvbkbc avatar jcmvbkbc commented on June 18, 2024

Is this right?

No. Take a look at the chapter 6.14 "Register Summary" in the esp32s3 TRM for the details.

from linux-xtensa.

zap8600 avatar zap8600 commented on June 18, 2024

Tell me if I'm wrong, but would this work?

#include <stdint.h>

// Define base address of GPIO matrix
#define GPIO_MATRIX_BASE 0x60004000

// Define GPIO matrix registers (offsets from base address)
#define GPIO_MATRIX_IN_CTRL 0x0
#define GPIO_MATRIX_OUT_CTRL 0x4
// ... Add more register offsets as needed

int main() {
    // Pointer to the GPIO matrix base address
    volatile uint32_t* gpio_matrix_ptr = (volatile uint32_t*)GPIO_MATRIX_BASE;

    // Example: Configure GPIO21 as an input from a specific source
    gpio_matrix_ptr[GPIO_MATRIX_IN_CTRL / 4] &= ~(0x1F << 10); // Clear bits 14-10
    gpio_matrix_ptr[GPIO_MATRIX_IN_CTRL / 4] |= (0x01 << 10);  // Set bits 14-10 to the source you want

    // Example: Configure GPIO22 as an output to a specific destination
    gpio_matrix_ptr[GPIO_MATRIX_OUT_CTRL / 4] &= ~(0x1F << 10); // Clear bits 14-10
    gpio_matrix_ptr[GPIO_MATRIX_OUT_CTRL / 4] |= (0x02 << 10);  // Set bits 14-10 to the destination you want

    // Add more configurations as needed...

    // Now GPIO21 and GPIO22 are configured according to your settings.

    // Add your main code here...

    return 0;
}

from linux-xtensa.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.