Rahix / avr-device

Register access crate for AVR microcontrollers
Apache License 2.0
168 stars 67 forks source link

Add patches for ATmega8 #112

Closed Rutherther closed 1 year ago

Rutherther commented 1 year ago

This PR adds patches for ATmega8 needed to implement ATMega8 to avr-hal easily.

Unfortunately I had to edit the vendor file, because there is a field WGM2 consisting of WGM21 and WGM20 that are not directly next to each other. Any idea on how to patch this correctly?

Rutherther commented 1 year ago

Hm. I am looking at the generated code and it doesn't seem that having a field on positions not directly to each others is even possible now.

Can a support for that be added and would that be desirable? Or should I just remove that and WGM2 will have to be configured directly without an enum?

Rutherther commented 1 year ago

ATmega8 uses the same register for UCSRC and UBRRH, the way to differentiate between them is that when setting UCSRC, you have to make URSEL (MSb) one. Is there a possibility to handle that automatically? Currently the generated code contains functions in usart.rs instead of fields

    #[doc = "0x17 - USART Control and Status Register C"]
    #[inline(always)]
    pub fn ucsrc(&self) -> &crate::Reg<ucsrc::UCSRC_SPEC> {
        unsafe {
            &*(((self as *const Self) as *const u8).add(23usize)
                as *const crate::Reg<ucsrc::UCSRC_SPEC>)
        }
    }
    #[doc = "0x17 - USART Baud Rate Register Hight Byte"]
    #[inline(always)]
    pub fn ubrrh(&self) -> &crate::Reg<ubrrh::UBRRH_SPEC> {
        unsafe {
            &*(((self as *const Self) as *const u8).add(23usize)
                as *const crate::Reg<ubrrh::UBRRH_SPEC>)
        }
    }

But it does not seem that it sets MSB to one automatically, that's understandable as there is nothing about that in the vendor files nor in patches.

Rutherther commented 1 year ago

Alright, I thought these problems could be solved, that was the reason it was a draft. I think it may be merged now.