1

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);
david_10001
  • 492
  • 1
  • 6
  • 22
  • How is your screen buffer ("framebuffer" is the common term) declared? What kind of display is it? Usually you will have e.g. `uint8_t framebuffer[DISPLAY_WIDTH * DISPLAY_HEIGHT * DISPLAY_DEPTH];`or something somewhere. This must be known by the code that draws stuff. – unwind May 22 '18 at 09:39
  • 1
    This is too broad, you are asking how to get some pixel from an unknown bitmap format, for an unknown screen, then how to write a whole UART driver or whatever. Please try to narrow the question down to one specific technical problem at a time, rather than "how do I do my whole project". – Lundin May 22 '18 at 09:46
  • Sorry, I know it's a bit vague. I'm working out of libraries that I'm having a hard time understanding. However, in my question I am just after how to print the address of a byte in the AVR-GCC terminal. – david_10001 May 22 '18 at 10:09
  • 2
    Your best bet is to learn how to use the AVR's serial port (UART) to send debugging data, and get a USB-to-serial adapter. Or try blinking an LED to communicate the debugging data. Also, if the location of `car_bitmap` is known at build time, you can look in the optional map file produced by the compiler to see where it is, and then do pointer arithmetic in your head to get the address of `car_bitmap[1]`. For example `car_bitmap` is an array of `uint8_t` integers, then `car_bitmap[1]` is just one byte after `car_bitmap`. – David Grayson May 22 '18 at 20:14

2 Answers2

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.

0___________
  • 60,014
  • 4
  • 34
  • 74
1

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • printf() doesn't seem to work with the AVR compiler unfortunately. I get no error when compiling, but the Cygwin terminal doesn't display anything. – david_10001 May 22 '18 at 11:48
  • @david_10001 `printf()`-debugging on embedded targets is a bit complicated, you need to dig through and figure out if there's code to connect `printf()` with a serial port, and so on. Also, a full `printf()` can be a bit heavy, so perhaps you're already using a trimmed-down standard library. It's not the compiler's responsibility, you need to figure out how it's implemented. – unwind May 22 '18 at 11:51