...
 
Commits (6)
......@@ -3,10 +3,10 @@
//--------------------------------------------------------------------------------------------------
struct Rectangle {
uint32_t x_min;
uint32_t x_max;
uint32_t y_min;
uint32_t y_max;
int32_t x_min;
int32_t x_max;
int32_t y_min;
int32_t y_max;
};
//--------------------------------------------------------------------------------------------------
......@@ -17,23 +17,31 @@ public:
min_cut_thickness_(min_cut_thickness), width_px_(to_px(width_)), height_px_(to_px(height_)),
min_cut_thickness_px_(to_px(min_cut_thickness_))
{
png_writer_.allocate(width_px_, height_px_);
png_writer_.allocate(width_px_ + 4 * min_cut_thickness_px_,
height_px_ + 4 * min_cut_thickness_px_);
png_writer_.set_all_pixels(255);
draw_int_rectangle(0, width_px_, 0, height_px_, 0);
}
uint32_t to_px(double x) {
return static_cast<uint32_t>(pix_per_mm_ * x);
int32_t to_px(double x) {
return static_cast<int32_t>(pix_per_mm_ * x);
}
void set_pixel(uint32_t x, uint32_t y, uint8_t value = 255) {
png_writer_.set_pixel(x, height_px_ - y - 1, value);
void set_pixel(int32_t x, int32_t y, uint8_t value = 255) {
png_writer_.set_pixel(2 * min_cut_thickness_px_ + x,
2 * min_cut_thickness_px_ + height_px_ - y - 1,
value);
}
void draw_rectangle(
uint32_t x_min, uint32_t x_max, uint32_t y_min, uint32_t y_max, uint8_t value = 255
void draw_int_rectangle(
int32_t x_min, int32_t x_max, int32_t y_min, int32_t y_max, uint8_t value = 255
) {
for (uint32_t x = x_min; x <= x_max; ++x) {
for (uint32_t y = y_min; y <= y_max; ++y) {
x_min = std::max(0, x_min);
x_max = std::min(width_px_, x_max);
y_min = std::max(0, y_min);
y_max = std::min(height_px_, y_max);
for (int32_t x = x_min; x < x_max; ++x) {
for (int32_t y = y_min; y < y_max; ++y) {
set_pixel(x, y, value);
}
}
......@@ -42,11 +50,11 @@ public:
void draw_rectangle(
double x_min, double x_max, double y_min, double y_max, uint8_t value = 255
) {
draw_rectangle(to_px(x_min), to_px(x_max), to_px(y_min), to_px(y_max), value);
draw_int_rectangle(to_px(x_min), to_px(x_max), to_px(y_min), to_px(y_max), value);
}
void draw_rectangle(Rectangle const& r, uint8_t value = 255) {
draw_rectangle(r.x_min, r.x_max, r.y_min, r.y_max, value);
draw_int_rectangle(r.x_min, r.x_max, r.y_min, r.y_max, value);
}
void draw_pad(double x_min, double x_max, double y_min, double y_max) {
......@@ -60,15 +68,21 @@ public:
png_writer_.write(filename);
}
void save_outline(char const* filename) {
png_writer_.set_all_pixels_black();
draw_int_rectangle(0, width_px_, 0, height_px_);
save(filename);
}
public:
PngWriter png_writer_;
double width_;
double height_;
double pix_per_mm_;
double min_cut_thickness_;
uint32_t width_px_;
uint32_t height_px_;
uint32_t min_cut_thickness_px_;
int32_t width_px_;
int32_t height_px_;
int32_t min_cut_thickness_px_;
};
//--------------------------------------------------------------------------------------------------
......@@ -81,48 +95,105 @@ int main() {
double pad_y_max;
// board params
double const width = 6;
double const width = 6.6;
double const height = 14;
double const ppmm = 50;
double const min_cut_thickness = 0.4;
double const ppmm = 50; // equivalent to 1270 ppi
double const min_cut_thickness = 0.38;
double const min_trace_thickness = 0.35;
Board board(width, height, ppmm, min_cut_thickness);
// SOIC dims
double const pad_width = 0.5;
double const pad_width = 0.6;
double const pad_height = 2.4;
//double const soic_width = 5;
double const soic_height = 7;
double const soic_pitch = 1.27;
// Draw the SOIC pads
double const soic_pos_x = 0.5 * (width - 3 * soic_pitch - pad_width);
double const soic_pos_y = 0.5 * (height - soic_height);
for (uint32_t i = 0; i < 4; ++i) {
pad_x_min = soic_pos_x + i * soic_pitch;
// SOIC pads
double const soic_x_min = min_trace_thickness + min_cut_thickness;
double const soic_x_max = soic_x_min + 3 * soic_pitch + pad_width;
double const soic_btm_y = 0.5 * (height - soic_height);
double const soic_top_y = height - soic_btm_y;
for (int32_t i = 0; i < 4; ++i) {
pad_x_min = soic_x_min + i * soic_pitch;
pad_x_max = pad_x_min + pad_width;
pad_y_min = soic_pos_y;
pad_y_max = pad_y_min + pad_height;
board.draw_pad(pad_x_min, pad_x_max, pad_y_min, pad_y_max);
pad_y_min = height - pad_y_max;
pad_y_max = pad_y_min + pad_height;
board.draw_pad(pad_x_min, pad_x_max, pad_y_min, pad_y_max);
pad_y_max = soic_btm_y + pad_height;
board.draw_rectangle(pad_x_min, pad_x_max, soic_btm_y, pad_y_max);
pad_y_min = soic_top_y - pad_height;
board.draw_rectangle(pad_x_min, pad_x_max, pad_y_min, soic_top_y);
}
// Cable attachment dims
/*
double const cable_pad_height = 2.4;
pad_x_min = (width - 2 * min_cut_thickness) / 3;
pad_x_max = pad_x_min + min_cut_thickness;
pad_y_min = 0;
pad_y_max = pad_y_min + cable_pad_height;
for (uint32_t x = to_px(pad_x_min); x < to_px(pad_x_max); ++x) {
for (uint32_t y = to_px(pad_y_min); y < to_px(pad_y_max); ++y) {
set_pixel(x, y);
}
}
*/
// Ground pads and traces
double const cable_pad_width = (width - 2 * min_cut_thickness) / 3;
double const cable_pad_height = soic_btm_y - min_cut_thickness;
double const bridge_offset = 0.5 * (pad_width - min_trace_thickness);
board.draw_rectangle(0, cable_pad_width, 0, cable_pad_height);
board.draw_rectangle(0, min_trace_thickness, 0, height);
board.draw_rectangle(soic_x_min + bridge_offset,
soic_x_min + bridge_offset + min_trace_thickness,
cable_pad_height,
cable_pad_height + min_cut_thickness);
board.draw_rectangle(0,
cable_pad_width,
soic_top_y + 2 * min_cut_thickness + min_trace_thickness,
height);
// Data pads and traces
double const data_pad_x_min = cable_pad_width + min_cut_thickness;
double const data_pad_x_max = data_pad_x_min + cable_pad_width;
board.draw_rectangle(data_pad_x_min, data_pad_x_max, 0, cable_pad_height);
board.draw_rectangle(data_pad_x_max,
soic_x_max + min_cut_thickness + min_trace_thickness,
cable_pad_height - min_cut_thickness,
cable_pad_height);
board.draw_rectangle(soic_x_max + min_cut_thickness,
soic_x_max + min_cut_thickness + min_trace_thickness,
cable_pad_height,
soic_btm_y + pad_height + min_cut_thickness);
board.draw_rectangle(soic_x_min + bridge_offset,
soic_x_max + min_cut_thickness + min_trace_thickness,
soic_btm_y + pad_height + min_cut_thickness,
soic_btm_y + pad_height + min_cut_thickness + min_trace_thickness);
board.draw_rectangle(soic_x_min + bridge_offset,
soic_x_min + bridge_offset + min_trace_thickness,
soic_btm_y + pad_height + min_cut_thickness,
soic_top_y + min_cut_thickness);
board.draw_rectangle(soic_x_min + bridge_offset,
data_pad_x_max,
soic_top_y + min_cut_thickness,
soic_top_y + min_cut_thickness + min_trace_thickness);
board.draw_rectangle(data_pad_x_min, data_pad_x_max, soic_top_y + min_cut_thickness, height);
// VCC pads and traces
double const vcc_pad_x_min = 2 * (cable_pad_width + min_cut_thickness);
// pad 1
board.draw_rectangle(vcc_pad_x_min,
width,
0,
// Note the fudge factor... It makes mods happy.
cable_pad_height - min_cut_thickness - min_trace_thickness - 0.025);
board.draw_rectangle(width - min_trace_thickness, width, 0, height);
// pad 2
board.draw_rectangle(vcc_pad_x_min,
width,
height - cable_pad_height,
height);
// pad extension
board.draw_rectangle(soic_x_max + min_cut_thickness,
width,
soic_top_y - pad_height - min_cut_thickness,
height - cable_pad_height);
double const vcc_pin_x = soic_x_min + soic_pitch + bridge_offset;
board.draw_rectangle(vcc_pin_x,
width,
soic_top_y - pad_height - min_cut_thickness - min_trace_thickness,
soic_top_y - pad_height - min_cut_thickness);
board.draw_rectangle(vcc_pin_x,
vcc_pin_x + min_trace_thickness,
soic_top_y - pad_height - min_cut_thickness,
soic_top_y);
board.save("node_board_traces.png");
board.save_outline("node_board_outline.png");
return 0;
}