P- and n-type doping in spontaneous chemical deposition