Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Characters #8

Open
h4llow3En opened this issue Mar 3, 2019 · 1 comment · May be fixed by #55
Open

Custom Characters #8

h4llow3En opened this issue Mar 3, 2019 · 1 comment · May be fixed by #55

Comments

@h4llow3En
Copy link

In my now abandoned project about the HD44780 I tried my luck with the following function to create custom characters. Maybe this is a bit of help to you.

static CGRAM_ADDRESS: u8 = 0x40;
...
    /// Creates a new custom character from a bitmap on the given `address`
    pub fn create_char(&self, address: u8, bitmap: [u8; 8]) -> Result<u8, &'static str> {
        // send new custom character to cgram address
        match address {
            0...7 => {
                // Just send the COMMAND command to the given address
                self.command(CGRAM_ADDRESS | address << 3);
                for row in &bitmap {
                    self.send_byte(bitmap[*row as usize], DATA);
                }
                Ok(address)
            },
            _ => Err("address must be between 0 and 7"),
        }

    }
@felipetavares
Copy link

felipetavares commented May 11, 2024

Just ported your function for the current version of the project (+ the esp-hal 1.0 support in another PR) @h4llow3En

pub fn create_char<D: DelayNs>(&mut self, address: u8, bitmap: [u8; 8], delay: &mut D) -> Result<u8> {
    // send new custom character to cgram address                                                     
    match address {                                                                                   
        0..=7 => {                                                                                    
            // Just send the COMMAND command to the given address                                     
            self.write_command(0x40 | address << 3, delay);                                           
            for row in &bitmap {                                                                      
                self.write_byte(*row, delay);                                                         
            }                                                                                         
            Ok(address)                                                                               
        }                                                                                             
        _ => Err(Error),                                                                              
    }                                                                                                 
}                                                                                                     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants