• Welcome to Andy's Workshop Forums. Please login or sign up.
 
April 27, 2024, 11:41:07 pm

News:

SMF - Just Installed!


Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - yaqwsx

1
stm32plus C++ library / How to use GPIO pins?
August 01, 2016, 02:43:41 pm
Hello,

I want to create a class for an external peripheral, which uses several GPIO pins. I want to let user to specify an arbitrary IO pins, which don't have to be on the same port and the class would initialized them. I read almost all examples and I searched through the library source code and I am not sure if I understood, how should the GPIOs be used. There are my observations:


  • There are the Gpio{A,B,C,D,E,F} classes, which can configure several IO pins. Is it possible to have multiple instances of one class? Won't they collide?


  • There is the GpioPinRef class, which I am not sure how to use. If I construct it directly (by base address and pin), is the port and pin correctly initialized? Or there has to be an instance of GpioX, which initializes the port and pin (and the pin instance can be obtained by GpioX::operator[])?


  • There is a pin map, which defines a structure for each pin. Could it be used in my program?



I am not sure, how to use these observations. The only way I see is to have an instance of GpioX for every port (owned by main function or the application class) and then pass GpioPinRef to the peripheral. In this way I however have to configure the pins outside the peripheral class, which I don't really like (user is responsible for the proper pin configuration). Is there a way for easy pin configuration inside the peripheral class? Could a pin map be used?

Is my way of thinking against the library style? If so, how should I manage GPIOs (initialize them and pass them to peripheral control classes) in "STM32Plus style"?

Thank you for your answer

PS: My last question - when all instances of classes representing peripherals on a bus (eg. GPIO and Timers on AHB2) are destructed, is the bus clock disabled or not?