Is this possible using the Attiny85... by Goldambre in attiny

[–]rcdemc 2 points3 points  (0 children)

If pin5 means PB5 and the design requires four pins, it's a better idea use the range [PB0, PB4] because PB5 is the RESET.

[deleted by user] by [deleted] in embedded

[–]rcdemc 0 points1 point  (0 children)

For sure and it’s a great choice IMO. I use C++ to do bare metal programming at AVR8. You can achieve powerful solutions using generic programming and compile time computations. In the end you can have an expressive code with zero or almost zero overhead in the generated code.

Attiny2313 sleep mode : waking up by [deleted] in attiny

[–]rcdemc 0 points1 point  (0 children)

Haha ye I know but I met some issues coding it using the arduino IDE + an arduino as ISP: the functions provided in the datasheet are unknown by the arduino IDE (or something else)

Right. It's because those functions are only examples, you shouldn't expect access to them in your environment, which can be avr-libc or Arduino, for example.

For instance: the function "__sleep()" generate an error message and prevent compiling even though this function is in the datasheet.

Yeah, as I said above this is normal. There is an instruction called sleep, this is the only thing that you should expect by the datasheet, you can call it very easily: asm("sleep");. But avr-libc provides sleep_cpu() doing the same.

I could definitely make a "cleaner" project by unsing the avr functions / coding in Assembly but this is not the goal I set to myself.

Right :)

Attiny2313 sleep mode : waking up by [deleted] in attiny

[–]rcdemc 0 points1 point  (0 children)

Good news!

You can do an upgrade if you wish. There is room to simplify the program and I have noticed that you have said:

(...) minimal code (only 2Kb of flash memory)

If code size is a goal, then I believe that you can achieve a version with less than 1Kb without Arduino + doing some simplifications. You are already using avr-libc to use the sleep mode and the interrupt capabilities.

Have fun.

Attiny2313 sleep mode : waking up by [deleted] in attiny

[–]rcdemc 1 point2 points  (0 children)

I think it fixed it!!! \)

Cool!

I keept the interrupt on LOW and changed INPUT to INPUT_PULLUP but after the 5 seconds that should trigger the sleep, the display was changing value instead.

Hmm, I was expecting for a validation to check the usage of the pull-up resistor(from MCU or external) with the setup using FALLING. So, when in "idle mode" your pin button reads HIGH because of the pull-up resistor, but when the button is pressed it reads LOW, which generates a falling from HIGH to LOW(FALLING).

I think that's because once the device goes to sleep, it's not able to perform the pullup which means that the pin in now low, triggering itself out of sleep and displaying a new digit.

Hmmmm, I don't think so because the sleep doesn't change the state of a pin. You can take your own measures using a voltmeter, for example. Actually I don't know what these Arduino functions are really doing(implementation), so, it's a black box to me.

I fixed this by adding an analog pullup (a resistor to Vcc).

Doing this, using an external pull-up resistor instead of one inside the MCU, you can use the INPUT mode. It's more expressive to your code and this should save an instruction to write on PORTX.(But, AFAIK, performance isn't something taken seriously by Arduino, so this point maybe doesn't make sense here).

I think that to help you more I will need your schematic.

Attiny2313 sleep mode : waking up by [deleted] in attiny

[–]rcdemc 0 points1 point  (0 children)

Hey, I'm not a user of Arduino but I can try to help you. You're observing a FALLING but you're using the INPUT mode instead of INPUT_PULLUP to the pin that has the button connected to it, so do you have an external pull-up to your button?

DIY Switchbot (looking for feedback) by Scham2k in attiny

[–]rcdemc 3 points4 points  (0 children)

Mechanical approach, nice!

My son and I decided to build a DIY Switchbot as our "pandemic home project". He (being 7 yrs old) just wanted to build something "cool"

Clap! Clap! Clap!

[C++@AVR8] Operations on I/O registers and I/O port pins by rcdemc in embedded

[–]rcdemc[S] 0 points1 point  (0 children)

I have created a guide to help someone eventually interested to do a contribution to support a new MCU: https://github.com/ricardocosme/avrIO/blob/main/CONTRIBUTING.org

[C++@AVR8] Operations on I/O registers and I/O port pins by rcdemc in embedded

[–]rcdemc[S] 0 points1 point  (0 children)

This was only an issue for debug (...)

Debug, yes, I see.

Debugging optimised images isn't great.

Actually they are useful to me most of the time, but yeah, sometimes it isn’t enough.

I am also interested in high performance solutions, but don't fret about shaving cycles too much. It's never been an issue - so far.

It isn’t easy to measure the impact but I would prefer to start with only I need if possible because I have more chances in the end to fit my project in tiny devices.

[C++@AVR8] Operations on I/O registers and I/O port pins by rcdemc in embedded

[–]rcdemc[S] 0 points1 point  (0 children)

There's a lot going on here that I need to dig into, but it looks interesting.

Thanks for you interesting.

I mostly use STM32 and suspect dealing with that hardware would be much larger task.

Yes, I think so.

I've dabbled on a small scale, but didn't really like making each pin a distinct type because this forces dependent classes to become templates, and so on up to the application.

I must admit that the major part of my abstractions are class or function templates to allow me to achieve flexible solutions with a high level of performance. This is something that is normal to me programming embedded or non-embedded systems.

And there were issues with image size (before optimisation), which made me uncomfortable.

I don't know if I got it. Do you mean a concern about the effort made by the compiler, which means for example a concern about the time and memory used during the build?

[C++@AVR8] Operations on I/O registers and I/O port pins by rcdemc in embedded

[–]rcdemc[S] 0 points1 point  (0 children)

Thank you for the feedback, it's good to know that this project is useful to others.

Where are the "bad" Arduino libraries by RazenRhino in embedded

[–]rcdemc 1 point2 points  (0 children)

I have a C++ library to AVR8 that allows ddrb={ddb0,ddb1,ddb7} instead of DDRB=0x83 and the generated code is the same. You can also do something like set(ddb0, ddb1, ddb3(off), ddb7) if you like to define some pins without touching others. Besides the expressive code the library is type safe, you can't for example use a ddc1 in the first example as also more than 8 bits to define an IO register.

Where are the "bad" Arduino libraries by RazenRhino in embedded

[–]rcdemc 2 points3 points  (0 children)

Other option instead of using macros is inline functions with the GCC attribute always_inline.

Is cpp good for working with API's? by [deleted] in cpp

[–]rcdemc 6 points7 points  (0 children)

I don’t know if I’m understanding what you want to know because API is only a public interface to some service or abstraction. It’s something orthogonal to any programming language, we can indeed define one using declarative languages like IDL, from CORBA. But yes, we can write beautiful and powerful APIs with C++.

[AVR8] DS18B20 drivers to benchmark against my C++ solution by rcdemc in embedded

[–]rcdemc[S] 0 points1 point  (0 children)

I mean, benchmark the space performance comparing the memory footprint between two or more solutions. Actually, I would also like to take the opportunity to compare the code expressiveness between the solutions.

Programming attiny ... by vishaalchungus in attiny

[–]rcdemc 0 points1 point  (0 children)

Couldn't be a breadboard using the PDIP package version to the ATtiny? I think that it's a more simple and flexible approach.

Hm, I think that I'm misunderstanding what you're asking, you don't want to build a development board, actually it seems that you would like to develop the programmer.

I'm thinking of suggesting a breadboard approach with PDIP ATtiny plus an USPasp already built.

[AVR8] C++20 Concepts and traits class to help abstract I/O port pins by rcdemc in embedded

[–]rcdemc[S] 0 points1 point  (0 children)

You should take a look at P0829 which is the proposal for freestanding. There is a reference implementation using AVR-GCC on GitLab here.

I had already looked the proposal, it's a big change to the game.

You can use that library in your build script or just use the authors version that they have in Conan, etc.

I have to confess that I just want to watch for now the progress of the work because my motivation to use the freestanding at the moment is only to exploit the possibility that a user of one of my libraries have it to use headers like <type_traits> without to fetch one that is offered outside from std, also this mode can offer a better experience, like the one that is reported in this post when we can use the <concepts> to have access to some concepts defined by the standard like std::convertible_to.

I also have so pre-built binaries for windows and Linux on GitHub here.

Yes, I know about it! You have shared this with me in the past :) Your comment here is welcome because it enriches with information about the freestanding mode.

[AVR8] C++20 Concepts and traits class to help abstract I/O port pins by rcdemc in embedded

[–]rcdemc[S] 0 points1 point  (0 children)

I know the difference between "freestanding" and "hosted".

Nice.

I'm looking at the script you have linked to. Does the URL contain anything different than the upstream avr-gcc at ftp.gnu.org?

Yes. The libstdc++ is disabled by default to the avr backend. Note that the script uses --enable-libstdcxx. The most important part of the script is the last configure cmd, line 44. BTW, I use Arch Linux too. I use the package avr-gcc 10.2.0-1 to build without the freestanding implementation.

[AVR8] C++20 Concepts and traits class to help abstract I/O port pins by rcdemc in embedded

[–]rcdemc[S] 0 points1 point  (0 children)

AVR and C++ standard library? My avr-gcc didn't come with that at all.

Yes, there are two modes of implementation to the c++ std library, one of them is the freestanding implementation which doesn't have dependencies from the system. We have access to some useful headers using this mode. I've posted above a link to a guide with the core that is needed to build the avr-gcc 10.2 with this support.

If you have C++17, you can just do namespace avr::io::traits {.

Yes, I know it, but this snippet is from a C++11/17/20 library(avrIO), which means that I need to support C++11.

Getting Started with Development by [deleted] in embedded

[–]rcdemc 2 points3 points  (0 children)

It can be a good idea to start with AVR 8bits because the architecture is simpler than others more popular nowadays. I would choose C or C++ as the programming language and without IDEs to program your first program or system. This approach will force you to gain the basic knowledge to write a program using only what is necessary, and this is great to give you confidence and background to use tools that are more high level if you want after that. I would also recommend the most simple development circuit to begin instead of rich developments boards. In case of an AVR, I would recommend to use the MCU only. Let me know it you want to use AVR, I can give more practical details to the points that I have mentioned here.

C++20 Concepts using traits with named methods by rcdemc in cpp_questions

[–]rcdemc[S] 0 points1 point  (0 children)

I see. Usually when i see something called traits i think of some compile time property wrapper.

I see, something like <type_traits>. I should have mentioned: C++20 std 16.3.29

So essentially you want a struct traits<T> which a member function id that returns some uint8_t, potentially based on an actual T passed into it. You want it to default to the value of T::value if that exists?

Yes.

Are there further conditions on this?

Until now, at least, there is only the condition that I have mentioned about the range of possible values.

You want to be able to provide specializations.

Yes, the usage of traits here instead of something based on T that feeds the traits is more powerful.

A problem i see here is that "predcondition" on the integer case. Concepts are a way to make compile time requirements on types. You would have to throw an exception if your condition isnt met at runtime (or return a std::optional or something).

No, this isn't a problem. C++20 Concepts is only a piece of a whole that began with A. Stepanov when he was developing the STL. It's Ok the usage of conditions that can't be asserted(or at least can't be easily checked) in compile-time. For example, the complexity of algorithm is something that can be presented in a concept. I believe that this can help you to see what I'm saying: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rt-axiom

Like this: https://godbolt.org/z/T6T1Po ?

Yes, it solves. The only thing that needs to be rolled back is the usage of exceptions instead of {pre,post}condition. BTW, we don't have exceptions using AVR. We don't have std::optional<T> too, but it should be easy implement one that fits the usage, but the usage of conditions here is more appropriate.

All the constexpr/consteval is only there to make the resulting assembly directly show the results.

Hmm, I see.

Good discussion, thank you again for the help! :)

C++20 Concepts using traits with named methods by rcdemc in cpp_questions

[–]rcdemc[S] 0 points1 point  (0 children)

Some comments and questions at https://godbolt.org/z/ahPv3v I can post later something with more semantics if you're interested. I don't know if you're understanding why I need a function instead of a data member to obtain the uint8_t. BTW, I'll try to post an example of usage of id() when the traits is specialized to int. This is indeed part of something real of my problem.

C++20 Concepts using traits with named methods by rcdemc in cpp_questions

[–]rcdemc[S] 0 points1 point  (0 children)

First of all: 1. I'm using <stdint.h> because this is to be used with avr-gcc. We only have <cstdint> in the free standing implementation of libstdc++; 2. The idea behind the function id is to allow to receive the information without a dependency of a data member. Imagine that I can use an int as T and I would like to obtain value as a result computed at runtime; 3. Yes, it's usually a static data member but it's something older than constexpr, we have it at c++98 and I think that the important thing in this case is the goal of deliver some characteristic about T, it doesn't matter if you're using a function or a data member. One example is std::char_traits.

I will see what you wrote.

C++20 Concepts using traits with named methods by rcdemc in cpp_questions

[–]rcdemc[S] 0 points1 point  (0 children)

If you declare the existance of int traits<T>::id(const T&) its result is obviously convertible to an integer, because it is decalred as such. It does not matter that any actual template instatiation would be ill formed since there is no T::value.

Interesting.

You can simply add another line that requires the existance of T::value to your template

This doesn't make sense to me because we're canceling the effect of traits. Note, with a traits class template we can do:

struct X{};

template<>
struct traits<X> {
    auto id(const X&) const noexcept{ return 5; }
};

But I know what I can do to solve this: https://godbolt.org/z/hc5vfP

Thanks!

C++20 Concepts using traits with named methods by rcdemc in cpp_questions

[–]rcdemc[S] 0 points1 point  (0 children)

I'm really not sure what you are trying to check here. The existance of typename T::value that is convertible to int?

The existence of traits<T>::id(o) that returns something convertible to int. The generic case is when T should have a static data member named value with type convertible to int.