 }
 
 //////////////////////////////////////////////////////////////////////////////
+// Code to handle the 'frequency' widget at screen top
+//////////////////////////////////////////////////////////////////////////////
+
+//-----------------------------------------------
+// Draw the frequency byte buffer to the screen.
+//     select  index of digit to highlight
+//
+// Updates all digits on the screen.  Skips leading zeros.
+//-----------------------------------------------
+
+void freq_show(int select=-1)
+{
+  bool leading_space = true;
+
+  tft.setFont(FONT_FREQ);
+  
+  for (int i = 0; i < NUM_F_CHAR; ++i)
+  {
+    if (i == select)
+      tft.fillRect(freq_char_x_offset[i], 2, CHAR_WIDTH+2, DEPTH_FREQ_DISPLAY-4, FREQ_SEL_BG);
+    else
+      tft.fillRect(freq_char_x_offset[i], 2, CHAR_WIDTH+2, DEPTH_FREQ_DISPLAY-4, FREQ_BG);
+                   
+    if ((freq_display[i] != '0') || !leading_space)
+    {
+      tft.drawChar(freq_char_x_offset[i], FREQ_OFFSET_Y, freq_display[i], FREQ_FG, FREQ_BG, 1);
+      leading_space = false;
+    }
+  }
+}
+
+//-----------------------------------------------
+// Unselect a digit in the frequency display.
+//     select  index of digit to unselect
+//-----------------------------------------------
+
+void freq_unselect(int select)
+{
+  Serial.printf("freq_unselect: select=%d\n", select);
+  tft.fillRect(freq_char_x_offset[select]-1, 2,
+               CHAR_WIDTH+1, DEPTH_FREQ_DISPLAY-4, FREQ_BG);
+  tft.setFont(FONT_FREQ);
+  tft.drawChar(freq_char_x_offset[select], FREQ_OFFSET_Y,
+               freq_display[select], FREQ_FG, FREQ_BG, 1);
+}
+
+//-----------------------------------------------
+// Fills the frequency char buffer from a given frequency.
+//
+//     buff  address of char buffer to fill
+//     freq  the frequency to put into the buffer
+//
+// Fills the buffer from the left with MSB first.
+//-----------------------------------------------
+
+void freq_to_buff(char *buff, unsigned long freq)
+{
+  int rem;
+
+  for (int i = NUM_F_CHAR - 1; i >= 0; --i)
+  {
+    rem = freq % 10;
+    freq = freq / 10;
+    buff[i] = '0' + rem;
+  }
+}
+
+//-----------------------------------------------
+// Gets an integer frequency from the frequency char buffer.
+//     buff  address of char buffer to fill
+//
+// Returns the buffer value as an unsigned long value.
+//-----------------------------------------------
+
+unsigned long freq_to_int(char *buff)
+{
+  unsigned long result = 0;
+
+  for (int i = 0; i < NUM_F_CHAR; ++i)
+  {
+    result = result * 10 + freq_display[i] - '0';
+  }
+
+  
+  return result;
+}
+
+//-----------------------------------------------
+// Draw the frequency 'thousands' markers
+//-----------------------------------------------
+
+void draw_thousands(void)
+{
+  tft.fillRect(FREQ_OFFSET_X+CHAR_WIDTH*2, 44, 2, 6, FREQ_FG);
+  tft.fillRect(FREQ_OFFSET_X+CHAR_WIDTH*5, 44, 2, 6, FREQ_FG);
+}
+
+//////////////////////////////////////////////////////////////////////////////
 // Code to handle the PixelVFO menus
 //////////////////////////////////////////////////////////////////////////////
 

// display constants - offsets, colours, etc
#define FONT_FREQ           (&FreeSansBold24pt7b) // font for frequency display
#define FONT_BUTTON         (&FreeSansBold12pt7b) // font for button labels

// various colours
#define ILI9341_LIGHTGREY   0xC618      /* 192, 192, 192 */

void menu_draw(struct Menu *menu)
{
  // clear screen and write menu title on upper row

  tft.fillScreen(SCREEN_BG);
  tft.setTextWrap(false);
  tft.setFont(FONT_MENU);

  // start drawing things that don't change
  tft.fillRect(0, 0, tft.width(), DEPTH_FREQ_DISPLAY, FREQ_BG);
  tft.setCursor(MHZ_OFFSET_X, FREQ_OFFSET_Y);
  tft.setTextColor(MENU_FG);

  // draw menuitems
  for (int i = 0; i < menu->num_items; ++ i)
  {
    int16_t x1;
    int16_t y1;
    uint16_t w;
    uint16_t h;
    int menuitem_y = DEPTH_FREQ_DISPLAY + i*MENUITEM_HEIGHT + MENUITEM_HEIGHT;
    
    tft.getTextBounds((char *) menu->items[i]->title, 0, 0, &x1, &y1, &w, &h);

    // write indexed item on lower row, right-justified
    tft.fillRect(0, menuitem_y - MENUITEM_HEIGHT, ts_width, MENUITEM_HEIGHT, MENU_BG);
    tft.setCursor(ts_width - w, menuitem_y);
    tft.print(menu->items[i]->title);
  }

  
}

//----------------------------------------
