I have a LPC1759 on a custom board. I'm trying to learn how to program that chip, but it's been a few years since I've done embedded programming. So far I have been able to setup with the GNU arm toolchain and VSCode and I been able to blink some LED, played with basic ADC, RIT, and a few other little things.
Since I'm quite rusty on C and embedded, I struggle sometimes with my understanding of things. I was browsing some other people's code, and I found this code snippet (also for lpc1759) and It raised some questions:
void set_FIOPIN(int port, int pin)
{
unsigned int *rp = (unsigned int *)(0x2009c018 + port*0x20);
*rp |= (1<<pin);
}
This code will SET a FIOPIN, if I understand It correctly. So, I was wondering if one could not also set a FIOPIN by this way:
LPC_GPIO1->FIOSET1 |= (1 << 23);
And why is one way preferred over the other?
Also, in the first snippet, the address 0x2009C018 (this is the address of FIO0SET, according to UM3690 manual, p 132) but why is this address not defined in the header file lpc17xx.h ? Anyone knows? Any special reason? I can see other things in lpc17xx.h like:
#define LPC_GPIO0_BASE (LPC_GPIO_BASE + 0x00000)
And I'm thinking, in the first code snippet that It would look better to use a defined address instead of hard coding an address. I dont know, what is a better practice here?
Also, would it not be better practice to use (uint32_t *) instead (unsigned int *)?
Just trying to expand my knowledge.
Best regards!