问题
I am trying to write a program that detects pixel level collision of bitmaps on a Teensy micro controller compiling with AVR-GCC. I am trying to work out how to calculate the position of a single byte of the bitmap on the screen and have been told I should be using pointers. I don't see the relationship between the physical address of a bitmap byte and it's position on the screen, but I would like to investigate. The problem is, I have no way of printing this address. AVR doesn't have printf and I don't know how to get it to display on the screen. Does anyone have a way of producing this address somehow in the terminal?
i.e. if I have a bitmap and want to print out the address of the first byte, what would I need to write to complete this:
??? *bit = &car_bitmap[1];
???("%??? ", bit);
回答1:
Use snprintf and send the string to the terminal. It is very costly on the AVR uC. If you use gcc address spaces extensions you may have to link the support for the long numbers.
回答2:
Assuming you have a working printf()
, this should work:
void * const bit = &car_bitmap[1];
printf("%p\n", bit);
Where %p
is how to print a void *
. Other pointer types should be cast to void *
in order to match, but I used a void *
for the address into the framebuffer anyway.
来源:https://stackoverflow.com/questions/50464420/how-to-find-the-address-of-a-variable-when-using-avr